Need to extract some lines from output via AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to extract some lines from output via AWK
# 1  
Old 06-10-2010
Need to extract some lines from output via AWK

Hello Friends,

I have got, this output below and i want to extract the name of symlink which is highlighted in red and the path above it highlighted in blue. At the end i want to append path and symlink.

Code:
/var/tmp/asirohi/jdk/jre
/var/tmp/asirohi/jdk/jre/.systemPrefs
/var/tmp/asirohi/jdk/jre/bin
/var/tmp/asirohi/jdk/jre/bin/classic
lrwxrwxrwx  1 asirohi user      9 2010-06-09 16:18 libjvm.a -> libjvm.so
/var/tmp/asirohi/jdk/jre/bin/headless
/var/tmp/asirohi/jdk/jre/bin/j9vm
lrwxrwxrwx  1 asirohi user      9 2010-06-09 16:18 libjdk.a -> libjvm.so
/var/tmp/asirohi/jdk/jre/bin/motif21
/var/tmp/asirohi/jdk/jre/bin/xawt
/var/tmp/asirohi/jdk/jre/lib
/var/tmp/asirohi/jdk/jre/lib/applet

So the output should be:-
Code:
/var/tmp/asirohi/jdk/jre/bin/classic/libjvm.a
/var/tmp/asirohi/jdk/jre/bin/j9vm/libjdk.a


I am new to awk, could you help me?

Thanks
Aditya


Moderator's Comments:
Mod Comment Use code tags please, ty.

Last edited by zaxxon; 06-10-2010 at 05:47 AM.. Reason: code tags
# 2  
Old 06-10-2010
Hi , Try this ...using perl

Code:
#!/usr/bin/perl

while (<>) {
chomp;
if ( /(\d+\:\d+)\s(.+?)\s\-\>/) { print $prev_line,"/",$2,"\n"; }
$prev_line=$_;
}

Run command
Code:
perl perlscript inputfile

# 3  
Old 06-10-2010
Try
Code:
$ awk '/^[^/]/{ print x"/"$(NF - 2) } { x=$0 }' inputfile
/var/tmp/asirohi/jdk/jre/bin/classic/libjvm.a
/var/tmp/asirohi/jdk/jre/bin/j9vm/libjdk.a

# 4  
Old 06-10-2010
Another approach:
Code:
awk '/->/{print s "/" $(NF-2)} {s=$0}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract lines from output

Hi everyone, I have the following string that repeats in a file. I want to get the following output : "CDN_NF2_SGW_INT_443" 172.23.120.40:443 source-address-translation { pool /Common/SNAT_EXTERNAL_62.179.94.194 and parse the file till the end . (3 Replies)
Discussion started by: liviusbr
3 Replies

2. Shell Programming and Scripting

awk to retain header lines in output

The awk below executes and produces the current output, which is correct, except I can not seem to include the header lines # and ## in the output as well. I tried adding !/^#/ thinking that it would skip the lines with # and output them but the entire file prints as is. Thank you :). file ... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

Remove lines from output in files using awk

I have two large files (~250GB) that I am trying to remove the where GT: 0/0 or 1/1 or 2/2 for both files. I was going to use a bash with the below awk, which I think will find each line but how do I remove that line is that condition is found? Thank you :). Input 20 60055 . A ... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

awk to output lines less than number

I am trying to output all lines in a file where $7 is less than 30. The below code does create a result file, but with all lines in the original file. The original file is tab deliminated is that the problem? Thank you :). awk 'BEGIN{FS=OFS=","} $7 < 30 {print}' file.txt > result.txt... (3 Replies)
Discussion started by: cmccabe
3 Replies

5. UNIX for Dummies Questions & Answers

awk - Extract 4 lines in Column to Rows Tab Delimited between tags

I have tried the following to no avail. xargs -n8 < test.txt awk '{if(NR%6!=0){p=""}else{p="\n"};printf $0" "p}' Mod_Alm_log.txt > test.txt I have tried different variations of the above, the problem is mixes lines together. And it includes the tags "%a and %A" I need them to be all tab... (16 Replies)
Discussion started by: mytouchsr
16 Replies

6. UNIX for Dummies Questions & Answers

Extract lines in awk

Hi, I have one file of the following format: TBCD, 1521, 14585236, NSDFC XSDF, 1845, 14525426, SDFFF SDFC, 4524, 14523655, SDNCV ASBC, 1845, 48754251, SDFFC ASBC, 1845, 54542512, SDFFF ASBC, 1845, 34212512, NSDFC ASBC, 1845, 16890234, ASFCH MNDG, 1896, 15842642, SFTDD SDFC, 8524,... (4 Replies)
Discussion started by: alex2005
4 Replies

7. Shell Programming and Scripting

extract nth line of all files and print in output file on separate lines.

Hello UNIX experts, I have 124 text files in a directory. I want to extract the 45678th line of all the files sequentialy by file names. The extracted lines should be printed in the output file on seperate lines. e.g. The input Files are one.txt, two.txt, three.txt, four.txt The cat of four... (1 Reply)
Discussion started by: yogeshkumkar
1 Replies

8. Shell Programming and Scripting

Awk to extract lines with a defined number of characters

This is my problem, my file (file A) contains the following information: Now, I would like to create a file (file B) containing only the lines with 10 or more characters but less than 20 with their corresponding ID: Then, I need to compare the entries and determine their frequency. Thus, I... (7 Replies)
Discussion started by: Xterra
7 Replies

9. Shell Programming and Scripting

AWK: How to extract text lines between two strings

Hi. I have a text test1.txt file like:Receipt Line1 Line2 Line3 End Receipt Line4 Line5 Line6 Canceled Receipt Line7 Line8 Line9 End (9 Replies)
Discussion started by: TQ3
9 Replies

10. Shell Programming and Scripting

Need awk to extract lines and sort

Hi, My data looks like this. CHR SNP BP A1 TEST NMISS OR STAT P 0 SNP_A-8282315 0 2 ADD 1530 1.074 0.7707 0.4409 0 SNP_A-8282315 0 2... (11 Replies)
Discussion started by: genehunter
11 Replies
Login or Register to Ask a Question