Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing number from beginning of a line

Status
Not open for further replies.

troythered

Technical User
Apr 2, 2009
19
0
0
US
I have output in a file that is in 4 line increments:
1st line has 19 digits, a period, then 4 digits.
The second, third, and 4th lines have Text & Numbers in them.

Sometimes the 1st line has an upper or lowercase letter, number, or symbol in front of the 19 digits that I require.

I need to strip the beginnings of the first line so that it is 19 digits, the period, then 4 more digits, all while not messing with the other lines. Would awk be able to do this, or something like sed?
 
Here is an awk suggestion:

Code:
awk '[green]/[0-9]{19}[.][0-9]{4}$/[/green] {[b]gsub[/b]([green]/^[^0-9]+/[/green],[red]"[/red][purple][/purple][red]"[/red])}{[b]print[/b]}' inputfile


You could do the same in sed, but because it doesn't understand Extended Regular Expressions (and you can't use the {<count>} syntax), the RE would become quite long.

Annihilannic.
 
Hi

The Awk way also needs some notes about intervals :
[ul]
[li]traditionally there were no intervals in regular expressions[/li]
[li]POSIX standard added them later[/li]
[li]older [tt]gawk[/tt] versions required [tt]-r[/tt] ( [tt]--re-interval[/tt] ) switch to use them[/li]
[li]since version 4.0.0 [tt]gawk[/tt] also has intervals enabled by default[/li]
[/ul]
While talking about GNU, GNU [tt]sed[/tt] with [tt]-r[/tt] ( [tt]--regexp-extended[/tt] ) switch will understand that regular expression.



Feherke.
 
Thank you for the replies. They have given me something to work with, I appreciate it very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top