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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with awk command, pleeeeze!

Status
Not open for further replies.

bhill4

MIS
Feb 9, 2011
2
US
Hello all,
I am trying to read a series of 50 text files, called

filename01A.txt
filename02A.txt
filename03A.txt
.. etc, up to
filename57A.txt

These files are long, but there is one occurance of the phrase "[distance]" and I want to grab the 12 characters (..not the 13th..etc) that follow to the right of the phrase "[distance]" and put that data into a file called "output.txt" as a new line of text.

However, right now, I can at least get a new file called "output.txt" to be made, but the data is crap... here is what I have:

ben@ben-VB: ~/Desktop/TEST$ for filename in *; do awk '$0 ~ "[steps]" {print $0}' "$filename" > "output.txt"; done

Any suggestions?
 
[tt]> one occur[red]e[/red]nce of the phrase "[distance]"
> awk '$0 ~ "[steps]"[/tt]

[distance], [steps], ... what is it exactly you're looking for?


HTH,

p5wizard
 
SORRY!!! "[steps]" should read "[distance]
 
Kind of tricky on the [ and ] which need escaping because they have special meaning for REs

Code:
awk '/\[distance\]/{
 sub(".*\\[distance\\]","",$0)
 print substr($0,1,12)
} filename???.txt


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top