unable to grep the reqd field


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers unable to grep the reqd field
# 1  
Old 07-23-2012
unable to grep the reqd field

hi all,
i have a data sm thg like this
Code:
28504    0    abc    148782859    42    101M nhmmmm ilopo abc 2345432

i want to get only the field which is just aftr abc i,e., 148782859, 2345432

i have used
Code:
grep  /abc\t[0-9]/ filename

to get that but its not working can any 1 help me out
# 2  
Old 07-23-2012
didn't I see this on Perl monks this morning...
Code:
egrep -o 'abc[[:space:]]*[0-9]+' ~/tmp/tmp.dat

# 3  
Old 07-23-2012
And if your egrep doesn't support the -o option (mine doesn't), you may try this:
Code:
awk '{for(i=1;i<NF;i++) if($i=="abc") printf("%s ",$(i+1));print ""}' inputfile

This User Gave Thanks to elixir_sinari For This Post:
# 4  
Old 07-23-2012
hiii thank you for the reply. for some thing like below
Code:
28504    0    abc    148782859    42    101M nhmmmm ilopo abc 2345432

i need the output row wise. in my eg abc would appear two times so the fields also should appear side by side
Code:
148782859   2345432

. the output for 2nd line is printed in the next line
# 5  
Old 07-23-2012
Quote:
Originally Posted by anurupa777
the output for 2nd line is printed in the next line
That's the effect of -o (only matching) output control option.
@Skrynesaver - is -o defined/specified by POSIX or is it GNU-only?
# 6  
Old 07-23-2012
Code:
perl -ne 'print "$1\n" while /abc\s+(.+?)\s/g' file

This User Gave Thanks to Scrutinizer For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to grep using wildcard in a file.

I wish to check if my file has a line that does not start with '#' and has 1. Listen and 2. 443 echo "Listen 443" > test.out grep 'Listen *443' test.out | grep -v '#' Listen 443 The above worked fine but when the entry changes to the below the grep fails... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. UNIX for Beginners Questions & Answers

Using grep for a particular field

Hi , I have a file as shown below : 1836 21000 01052019 BH90P.TEMP.DA1836.FTP W NULL S 1836 22000 01052019 BH90P.TEMP.DA1836.FTP W 1836/21000 ... (2 Replies)
Discussion started by: krishnaswarnkar
2 Replies

3. Shell Programming and Scripting

Unable to do grep in a script

Hi, I am trying to grep a filename from a script after taking the file name and other variables as keyboard input .When I run the grep command with the same filename on the prompt, it runs fine, but it is either not giving me the correct output or not running at all from the script using the... (13 Replies)
Discussion started by: dsid
13 Replies

4. Shell Programming and Scripting

Unable to grep the process

I have user1 run a script called logginexpert.sh while has this line of code sleep 888I then login to another putty session with another user2 and try to grep for the logginexpert.sh process using ps -ef | grep exSunOS mymac 5.11 11.2 sun4u sparc SUNW,SPARC-Enterprise But, i dont get any... (20 Replies)
Discussion started by: mohtashims
20 Replies

5. UNIX for Dummies Questions & Answers

Unable to grep

I have a file with 2 lines of code Rome is in Romeo Romeo is in Rome How do I grep, so that only last line would be the outcome. sample output Romeo is in Rome I have tried with all possible greps but its resulting in both the lines in output. Please help. (6 Replies)
Discussion started by: gotamp
6 Replies

6. Shell Programming and Scripting

unable to match grep pattern

Hi All, I am trying to select all files in a directory which are not with .gz extension . for which I am using below script , but its rejecting both .gz and .z extension files,as in each letter is considered separately. PFB ls -lrt | awk '{print $9}'| egrep "^IRAMS.*$" please suggest... (1 Reply)
Discussion started by: Jcpratap
1 Replies

7. Shell Programming and Scripting

grep for a particular field

Hi All, I have the following in a text file #---- Set Silent License Acceptance #---- Accept license agreement: remove # sign #---- example: LICENSE_ACCEPTED=true #---- if the LICENSE_ACCEPTED is anything other then true the installation will exit #---- no log... (2 Replies)
Discussion started by: dbashyam
2 Replies

8. Shell Programming and Scripting

Unable to populate subject field of the email while using sendmail

Hi, Can anyone kindly provide some information about how to populate the subject field of the email while using the sendmail utility ? Itried the following command line argument : echo -e "Body of the email" | /usr/lib/sendmail -f from@from.com -t to@to.com -s " Subject of the email" ... (4 Replies)
Discussion started by: sdiptanil
4 Replies

9. HP-UX

Help Reqd

Hi I am facing the problem where my HP Unix system date is in accordance with the current date but the logs written by the same is of previous time stamp. Eg. System Date - Thu Mar 15 18:00:04 IST 2007 Syslogs - Mar 15 12:30:10 mac@1 ftpd: FTP LOGIN FROM xx.xxx.xxx.xx , main The ftp... (1 Reply)
Discussion started by: PradeepRed
1 Replies

10. Shell Programming and Scripting

unable to grep the following pattern

I have the following line in file1 elif ; then now if i try to grep this using following command grep -e "elif ; then" file1 it is showing nothing... how to grep such patterns (2 Replies)
Discussion started by: suri
2 Replies
Login or Register to Ask a Question