1834052 Members
2593 Online
110063 Solutions
New Discussion

Re: awk cmd

 
SOLVED
Go to solution
Jon Thomas_1
Occasional Contributor

awk cmd

I am attempting to extrapolate data from a large 20 meg text file by using the awk command. For $1 of each row there are 7 digit numbers. I am trying to extract selective consecutive lines of data and >> to fileXYZ by defining the range of numbers in $1 i.e. [43210-43310] that is desired - Is there a simple way of accomplishing this without doing complicated loop statements?
4 REPLIES 4
Rodney Hills
Honored Contributor

Re: awk cmd

ranges can be done-

awk '/^43210/,/^43310/{ print}' yourfile

HTH

-- Rod Hills
There be dragons...
Sundar_7
Honored Contributor

Re: awk cmd


you can use sed too

sed -n '/^43210/,/^43310/p' input >> output

Learn What to do ,How to do and more importantly When to do ?
KapilRaj
Honored Contributor

Re: awk cmd

Is this a simple way ?.

If you want to get lines of yourfile from $FROM_LINE to $TO_LINE,

cat yourfile |head -$TO_LINE |tail -`echo "$TO_LINE - $FROM_LINE " |bc`

Regds,

Kaps
Nothing is impossible
SANTOSH S. MHASKAR
Trusted Contributor
Solution

Re: awk cmd

I assume the Date at $1 that u want to fetch to be
00043210 and 00043310 since u have mention that $1 is a 7 digit num.
If so then try this

$ cat Your_text_file|awk -F Field_seperator '$1 >= 43210 && $1 <= 43310 {print $0}' >> XYZ

if u have fields seperated by white spaces then try this

$ cat Your_text_file|awk '$1 >= 43210 && $1 <= 43310 {print $0}' >> XYZ


-Santosh