Re: Extract a substring of n digits from a string
From: Janis Papanagnou (Janis_Papanagnou_at_hotmail.com)
Date: 10/27/05
- Next message: da: "Re: Using awk or perl or sed to format/combine rows"
- Previous message: da: "Re: Using awk or perl or sed to format/combine rows"
- In reply to: Giacomo: "Extract a substring of n digits from a string"
- Next in thread: Giacomo: "Re: Extract a substring of n digits from a string"
- Reply: Giacomo: "Re: Extract a substring of n digits from a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 Oct 2005 02:16:53 +0200
Giacomo wrote:
> I need to extract a substring of n adjacent digits from every single
> line of a file. The position of the n digits are different from line to
> line.
What type of shell or programs you do have to use?
What have you tried to program thus far?
General outline, for example...
Depending on whether the shell/tool/program supports extended regular
expressions or not you have to either define a regexp like [0-9]{n} or
construct one from n sequences of [0-9]. This regexp must be embedded
within white space [ \t] or non-numerical patterns [^0-9] depending on
your requirements. Take care of the line boundaries, so you'll likely
have to consider start of line ^ for the left and end of line $ for
the right boundary. Finally extract the substring from the matching
part. Consider to add spaces to the front and read of the input line
to simplify the matching and extraction of the substring pattern.
> For example:
>
> asdasd 123 asd 191991 1234
> lijoioi 4567 asdi 67567 iojoii
>
> For n=4 the result for each line must be 1234 e 4567.
Janis
- Next message: da: "Re: Using awk or perl or sed to format/combine rows"
- Previous message: da: "Re: Using awk or perl or sed to format/combine rows"
- In reply to: Giacomo: "Extract a substring of n digits from a string"
- Next in thread: Giacomo: "Re: Extract a substring of n digits from a string"
- Reply: Giacomo: "Re: Extract a substring of n digits from a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|