amahajan1981
asked on
grep between 3rd and 4rth comma
Hi
Text files look like this :
689:2006/07/12 01:08:06,5,espresso,149219 7335,star_ schema_log ,0.198698, 0.394908,0 .004487590 90909091,8 8,1.466666 66666667
689:2006/07/12 01:08:06,5,espresso,149219 7336,star_ schema_log ,0.198698, 0.394908,0 .004487590 90909091,8 8,1.466666 66666667
689:2006/07/12 01:08:06,5,espresso,149219 7337,star_ schema_log ,0.198698, 0.394908,0 .004487590 90909091,8 8,1.466666 66666667
I wanted to grep only word star_schema_log between 3rd and 4rth comma ..... how can i do this!
Regards
Anand
Text files look like this :
689:2006/07/12 01:08:06,5,espresso,149219
689:2006/07/12 01:08:06,5,espresso,149219
689:2006/07/12 01:08:06,5,espresso,149219
I wanted to grep only word star_schema_log between 3rd and 4rth comma ..... how can i do this!
Regards
Anand
use grep to get the lines you need (if you need to select only certain lines from a file), and then use awk to parse the lines.
or, use can use "cut" along with grep... grep will select the lines you need and cut can parse the lines
ASKER
i dont want to select lines all lines have "," as delimeter...
i just wanted to get a word from 3rd and 4rth ","
I am a beginner in unix...just started to read abt awk and sed
regards
Anand
i just wanted to get a word from 3rd and 4rth ","
I am a beginner in unix...just started to read abt awk and sed
regards
Anand
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
just 90%? ha, only kidding tacticalvehicle. Im so just to piping output from cat, I forget u can do the way u did
thanks for the recommendation though, appreciated!
thanks for the recommendation though, appreciated!
Print all lines where the 4th field matches a pattern:
awk -F"," '/ $4 == "star_schema_log" {print $0}' /pathto/file.log
awk -F"," '/ $4 == "star_schema_log" {print $0}' /pathto/file.log
The simplest solution is as someone above suggested: cut does it simply and correctly. You tell it that your delimiter is the comma, and that you want field number 5:
cut -d, -f5 file.txt
In fact, cut is really clever, in that you can pick out only the fields you want, e.g. to grab fields 1, 5, 6 and 7, you can do:
cut -d, -f1,5-7 file.txt
cut -d, -f5 file.txt
In fact, cut is really clever, in that you can pick out only the fields you want, e.g. to grab fields 1, 5, 6 and 7, you can do:
cut -d, -f1,5-7 file.txt
# quick&dirty
awk -F, '{print $4}' /path/to/file.log|grep pattern
# the awk way
awk -F, '/'pattern/'{print}' /path/to/file.log
awk -F, '{print $4}' /path/to/file.log|grep pattern
# the awk way
awk -F, '/'pattern/'{print}' /path/to/file.log
ASKER
Thnks guys for ur help!!
regards
Anand
regards
Anand