How to print Specific keyword, by using awk?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print Specific keyword, by using awk?
# 1  
Old 03-09-2012
Tools How to print Specific keyword, by using awk?

How to print Specific keyword, by using awk.?

Code:
prime:root:[/usr/home/myserver/$ cat input.log 
1620002_M_20120309033204_78.txt
1620002_M_20120309033232_1457.txt
1620002_M_20120309033240_10000.txt
1620002_M_20120309033241_10000.txt
1620002_M_20120309033242_5985.txt
1620002_M_20120309033243_307.txt
1620002_M_20120309033246_10000.txt
1620002_M_20120309033247_10000.txt
1620002_M_20120309033248_10000.txt
1620002_M_20120309033249_10000.txt
1620002_M_20120309033250_3760.txt
1620002_M_20120309033251_692.txt
1620002_M_20120309033254_6656.txt
1620002_M_20120309033255_157.txt
1620002_M_20120309033302_696.txt
1620002_M_20120309033303_127.txt
1620002_M_20120309033304_7408.txt

I want output.
Code:
78
1457
10000
10000
5985
307
10000
10000
10000
10000
3760
692
6656
157
696
127
7408

I try with command
Code:
cat input.log |awk -F"_" '{print$4}'

Please Guide Line.

Thank
# 2  
Old 03-09-2012
Code:
 awk -F'[_.]' '{print $4}' inputfilename > newfilename

# 3  
Old 03-09-2012
Quote:
Originally Posted by jim mcnamara
Code:
 awk -F'[_.]' '{print $4}' inputfilename > newfilename

I Try but not work.
# 4  
Old 03-09-2012
In what way does it "not work"?

What's your operating system?

Have you tried nawk instead of awk?
# 5  
Old 03-09-2012
Why awk?
Code:
while IFS='.' read a b; do echo ${a##*_}; done < input.log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print string if tag is specific value

In the below awk I am trying to print expName only if another tag planExecuted is true. In addition to the expName I am also printing planShortID. For some reason the word experiment gets printed so I remove it with sed. I have attached the complete index.html as well as included a sample of it... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

Print all lines between two keyword if a specific pattern exist

I have input file as below I need to check for a pattern and if it is there in file then I need to print all the lines below BEGIN and END keyword. Could you please help me how to get this in AIX using sed or awk. Input file: ABC ******** BEGIN ***** My name is Amit. I am learning unix.... (8 Replies)
Discussion started by: Amit Joshi
8 Replies

3. UNIX for Dummies Questions & Answers

How to print specific range using awk?

I want to print specific range of rows and then its columns using awk command. lets say if a file contain 15 line then i need to print line 5 to 9. awk '{print;for( NR>=5&&NR<=9); do; print "<tr>\n<td>"$1"</td><td>"$2"</td><td>"$3"</td>\n</tr" done}' xyz.csv not sure what's wrong... (9 Replies)
Discussion started by: amyt1234
9 Replies

4. Shell Programming and Scripting

Print a specific length using awk

Hello, I have the following input data: A C AA GG A G CG AG the code I tried: awk -F" " '{ if ((length($1==1) && (length($2==1))) input_file is not working, I need the output to be (such that only the columns containing one letter are printed) A C A G Any help would be appreciated! (5 Replies)
Discussion started by: Rabu
5 Replies

5. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

6. Shell Programming and Scripting

Print unique names in a specific column using awk

Is it possible to modify file like this. 1. Remove all the duplicate names in a define column i.e 4th col 2. Count the no.of unique names separated by ";" and print as a 5th col thanx in advance!! Q input c1 30 3 Eh2 c10 96 3 Frp c41 396 3 Ua5;Lop;Kol;Kol c62 2 30 Fmp;Fmp;Fmp ... (5 Replies)
Discussion started by: quincyjones
5 Replies

7. Shell Programming and Scripting

Find and print specific date with awk

hi all I would like to help me find the problem with this script to find and print to the screen a specific date of a log file that I have on my server, the date it is received as the first argument in the script $ 1 Here I show you a few lines that made ​​the idea of ​​my log file: ****... (4 Replies)
Discussion started by: gilmore666
4 Replies

8. Shell Programming and Scripting

awk print specific columns one row at a time

Hello, I have the following piece of code: roleName =`cat $inputFile | awk -F';' '{ print $1 }'` roleDescription =`cat $inputFile | awk -F';' '{ print $2 }'` roleAuthProfile =`cat $inputFile | awk -F';' '{ print $3 }'` mappedUserID (5 Replies)
Discussion started by: pr0tocoldan
5 Replies

9. Shell Programming and Scripting

To print a specific line in Shell or awk.

Hi, I want to echo the 15th line from a file named as abc.txt, also i want to echo only the values in that line not the line number. Thanks in advance:) (4 Replies)
Discussion started by: tushar_tus
4 Replies

10. Shell Programming and Scripting

How to print specific lines with awk

Hi! How can I print out a specific range of rows, like "cat file | awk NR==5,NR==9", but in the END-statement? I have a small awk-script that finds specific rows in a file and saves the line number in an array, like this: awk ' BEGIN { count=0} /ZZZZ/ { list=NR ... (10 Replies)
Discussion started by: Bugenhagen
10 Replies
Login or Register to Ask a Question