Grepping A Specific Column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grepping A Specific Column
# 1  
Old 11-17-2009
Grepping A Specific Column

Hello,

I have a log file that outputs the data below. I would like to grep and display the data where column is equal '148.'

I've searched the forum, and couldn't find any answers.
I've tried all the grep switches and I get the same result as the log.
I'm thinking I might have to use an if statement and grep; I'm working on a "one-liner" and it's taking me some time. Please help!

log
XJLGZ|380377|2|148|4|1500000|040|21|5|
LGCZL|380696|2|148|3|1500000|100|23|5|
XJLMW|314873|2|20|2|1500000|040|21|5|
XTQCW|381585|2|148|4|1500000|300|12|5|
Z6B65|741481|2|18|4|81500000|310|2|1|

Desired Output
XJLGZ|380377|2|148|4|1500000|040|21|5|
LGCZL|380696|2|148|3|1500000|100|23|5|
TQCW|381585|2|148|4|1500000|300|12|5|
# 2  
Old 11-17-2009
Hi, here are a couple of options

Code:
awk -F'|' '$4==148' infile

Code:
grep '^\([^|]*|\)\{3\}148|' infile

Code:
sed -n '/^\([^|]*|\)\{3\}148|/p' infile


Last edited by Scrutinizer; 11-17-2009 at 03:19 PM..
# 3  
Old 11-17-2009
Thank you very much! That was simple.

---------- Post updated at 01:31 PM ---------- Previous update was at 01:24 PM ----------

The code below should allow me to display just column 1, correct?
Could I also display and save to a file using tee? I'll give it try.

Code:
awk -F'|' '$4 == 148' infile |awk '{print ($1)}'

Thanks for your help!

---------- Post updated at 01:33 PM ---------- Previous update was at 01:31 PM ----------

Oops wasn't paying attention to the first AWK! I'll have to try something different.
# 4  
Old 11-17-2009
It should work if you use the same field separator in the second awk. But you do not require a pipe:
Code:
awk -F'|' '$4==148{print $1}' infile

# 5  
Old 11-17-2009
Code:
cut -d "|" -f 1  desired_infile



---------- Post updated at 02:54 PM ---------- Previous update was at 02:18 PM ----------

Excellent, this work absolutely perfect! I can now tee the data

Thanks for your help Scrutinizer! I'll be testing those examples you sent, just so I become more familiar. LOL! I'm a noob as you can tell!

Code:
awk -F'|' '$5==148 {print $1}' infile

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

2. Shell Programming and Scripting

Grepping non-alpa-numerics from first column only

I have data in the following tab-separated format (consists of 200 columns all together, this is just a sampling) </s> 0.001701 0.002025 0.002264 0.001430 -0.001300 . -0.205240 0.177341 -0.426209 -0.661049 -0.048884 0.027032 the -0.159145 0.084377 0.056968 0.050934 0.160689 of -0.230698... (7 Replies)
Discussion started by: owwow14
7 Replies

3. UNIX for Dummies Questions & Answers

Grepping al values of a particular column in a file

Name Num_free Num_active Pct_act Max_Used Reuse_cnt Instance_Name --------------------------------- --------------- ----------- ------- ----------- ----------- ------------------------------ additional network memory 0 ... (2 Replies)
Discussion started by: Rajeshneemkar
2 Replies

4. Shell Programming and Scripting

Grepping multiple strings from one column

I have 3-column tab separated data that looks like the following: act of+n-a-large+vn-tell-v 0.067427 act_com of+n+n-a-large-manufacturer-n 0.129922 act-act_com-com in+n-j+vn-pass-aux-restate-v 0.364499666667 com nmod+n-j+ns-invader-n 0.527521 act_com-com obj+n-a-j+vd-contribute-v 0.091413... (2 Replies)
Discussion started by: owwow14
2 Replies

5. Shell Programming and Scripting

Printing next two lines from a file after grepping a specific pattern

Hi I have a file like # vi require.txt 1,BANK,Read blocks that cycle. yellow Read blocks. 2,ACCOUNT,Finished Red Finished . 3,LOAN, pipe white pipe 4,PROFIT,Resolve. black Resolve Am using like cat require.txt | grep -w ACCOUNTThe output I get is (8 Replies)
Discussion started by: Priya Amaresh
8 Replies

6. Shell Programming and Scripting

Grepping a specific row from a file

Hi I have output of a command saved in a file.. # cat /file.txt System: cu=4 ent=0.1 mode=on cu min u s w i 0 500 0.1 0.3 0.5 0.1 1 200 0.5 0.2 0.3 0.0 By using ksh, what I need to do is, I need to grep the u,s,w and i... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

7. Programming

Grepping a column from multiple file

I have 20 files that look pretty much like this: 0.01 1 3822 4.97379915032e-14 4.96982253992e-09 0 0.01 3822 1 4.97379915032e-14 4.96982253992e-09 0 0.01 2 502 0.00993165137406 993.165137406 0 0.01 502 2 0.00993165137406 993.165137406 0 0.01 4 33 0.00189645523539 189.645523539 0 0.01 33 4... (5 Replies)
Discussion started by: kayak
5 Replies

8. Shell Programming and Scripting

Assigning a specific format to a specific column in a text file using awk and printf

Hi, I have the following text file: 8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm 9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm 10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm 11 T1mapping_flip15 ok 128 108 30... (2 Replies)
Discussion started by: goodbenito
2 Replies

9. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

10. Shell Programming and Scripting

Grepping for filenames containing value in specific segment within file

I am trying to grep for filenames containing a specific value within a particular segment. The lines containing the segment I'm looking through reads like "HL^1^^1^1", "10^9^9^0", and "HL^11^4^8^1". I would like to find the data that contains only the number nine after the third caret where the... (4 Replies)
Discussion started by: HLee1981
4 Replies
Login or Register to Ask a Question