Hi
Can any one pls tell me how to grep this line
POPULATION,69691,20120509
I want the number 69691 from the above line.
How to grep from the first comma till the next comma.
Thank You.
Hi
Can any one pls tell me how to grep this line
POPULATION,69691,20120509
I want the number 69691 from the above line.
How to grep from the first comma till the next comma.
Thank You.
grep doesn't understand columns, but awk does.
awk -F, '{ print $2 }' filename
Other tools you could use include cut.
Using regex:
sed "s/[^,]*,\([^,]*\),.*/\1/" filename
Hi Sir
They are 4 lines in the file.
One line is what i mentioned earlier
POPULATION,69691,20120509
From each line i just need to get the second value,
I studied the awk command and understood what you mean,
But i need to do it for all 4 lines in that file and each line based on the first word..ie., POPULATION and need 69691 from that line for further scripting.
How do I use awk command and see whether the second value is not 0.
here 69691 is not 0..then i proceed to do somemore scripting.
Thank You...I learnt a new command awk after your post.
Can you pls, help me with writing it for the above line and matching whether the second line is not 0.
Can you post the entire file?
Sir
basically this is an Audit file, which lets me know what each file contains
first column is the file name"POPULATION", second column is number of records (i shoudl see whether it is >0)(ie., means the file contains data or not) and the third column is date when the file was produced.(which i dont need)
Based on the Audit file results..i take one more step further.
POPULATION,69831,20120427
CITIZENS,78692,20120427
PERMANENT,0,20120427
COLLEGEKIDS,151891,20120427
The file contains the above 4 lines..i have to get the second column for
each line and if it is 0, stop the processing for that line.
POPULATION is > 0
and
PERMANENT IS 0....> SO NO PROCESSING FOR PERMANENT.
Thank You.
#! /bin/bash
while read line
do
if [ $(echo $line | cut -d, -f2) -gt 0 ]
then
<more_processing>
fi
done < audit_file.txt
how do you process your lines ? any mathematical calculation ?
awk '$2>0{print $2}' input.txt
If you want to loop over the lines, you can use plain while read.
while IFS="," read G VAR G
do
echo $VAR
done < inputfile