Need help in solving to obtain desired print output using awk or perl or any commands, Please help!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in solving to obtain desired print output using awk or perl or any commands, Please help!!
# 1  
Old 05-19-2015
Need help in solving to obtain desired print output using awk or perl or any commands, Please help!!

I have an file which have data in lines as follows

Code:
ad, findline=24,an=54,ab=34,av=64,ab=7989,ab65=34,aj=323,ay=34,au=545,ad=5545
ab,abc,an10=23,an2=24,an31=32,findline=00,an33=23,an32=26,an40=45,ac23=5,ac=87,al=76,ad=26
ab,abc,an1=23,ar=57,an10=24,findline=00,at=39,am=67,an31=35,an33=23,an3=26,an40=95,ac=55

I want to obtain output as below

Code:
findline=00 an10=23 an31=32 an40=45
findline=00 an10=24 an31=32 an40=95


i have been using the below commands before, with the below output

Code:
gzip -dcr/file path/filename.gz | grep findline=00 | awk -F, '{print $1,$4,$6,$7}' | sort -n | uniq -c


OUTPUT
======
Code:
1 findline=00 an10=23 an31=32 an40=45
1 findline=00 an10=24 an31=32 an40=95


INPUT File Lines (eg)
Code:
findline=02,ab,abc,an19=23,an1=28,an31=36,an40=41,an33=22,an32=28,ac23=53,am=57,al33=56,an3=56
findline=04,ab,abc,an14=24,an1=27,an31=334,an40=98,ar33=59,an32=22,ac23=19,am=17,al33=13,an3=76,ac=55
findline=00,ab,abc,an10=23,an1=24,an31=32,an40=45,an33=23,an32=26,ac23=5,am=87,al33=76,an3=16
findline=00,ab,abc,an10=24,an1=23,an31=35,an40=95,ar33=57,an32=24,ac23=39,am=67,al33=23,an3=26,ac=55


But since my variable that I am looking out for an10, an31 and an40 are in different fields, in the new files, I cant obtain an uniform output with the above command.
Any idea how to get the desired output using the desired command

Last edited by Don Cragun; 05-19-2015 at 03:48 AM.. Reason: Add CODE and ICODE tags again.
# 2  
Old 05-19-2015
Please use code tags as required by forum rules!

It's not that easy to infer your requirements from what you've posted, so I hope I'm on the right path. Why don't you help us help you by thinking twice and giving a detailed and precise spec?
Try to pipe your data through
Code:
awk '
BEGIN           {FS=","
                 for (i=split("findline,an10,an31,an40", t); i; i--) FLD[t[i]]=i
                }

/findline=00/   {for(i=1; i<=NF;i++)    {T=$i; sub (/=.*$/, _, T)
                                         if (T in FLD )
                                         OUT[FLD[T]]=$i
                                        }
                 for (f=1; f<=4; f++) printf "%s ", OUT[f];
                 print ""
                }
'
findline=00 an10=23 an31=32 an40=45 
findline=00 an10=24 an31=35 an40=95

# 3  
Old 05-19-2015
You are on right path, but need an input command like the one provided
# 4  
Old 05-19-2015
Since you only supplied the output from your gzip command, there was no way for us to test with that command in scripts we were trying to build and test for you.

With what RudiC provided and the pipeline that we thought you had created, we assumed you would be able to change the first line of RudiC's script from:
Code:
awk '

to:
Code:
gzip -dcr/file path/filename.gz | awk '

to get what you want.

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
This User Gave Thanks to Don Cragun 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

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

2. Shell Programming and Scripting

Print if found non-desired result

I have a result like this root@server # grep -rl maldet /etc/cron* /etc/cron.d/maldet_daily /etc/cron.d/malcron /etc/cron.d/malcrondaily /etc/cron.d/malcronweekly What I need is, I need an if/else condition such that, if there is any output other than /etc/cron.d/maldet_daily in the... (8 Replies)
Discussion started by: anil510
8 Replies

3. Shell Programming and Scripting

Print Value between desired html tag

Hi, I have a html line as below :-... (6 Replies)
Discussion started by: satishmallidi
6 Replies

4. Shell Programming and Scripting

Unable to obtain the desired output

Hi, I am unable to get beyond the exit function. The shell script is used to look for masked files and copy paste them to another location. Please refer to the code below for more information. Thanks Brinjit #!/usr/bin/ksh... (10 Replies)
Discussion started by: brinjit
10 Replies

5. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

6. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

7. Shell Programming and Scripting

awk syntax mistake doubles desired output

I am trying to add a line to a BASH shell script to print out a large variable length table on a web page. I am very new to this obviously, but I tried this with awk and it prints out every line twice. What I am doing wrong? echo "1^2^3%4^5^6%7^8^9%" | awk 'BEGIN { RS="%"; FS="^"; } {for (i =... (6 Replies)
Discussion started by: awknewb123
6 Replies

8. Shell Programming and Scripting

using perl or awk to print output

suppose u have file File A A -> G C->D A -> R P->A File B A=1 C=2 D=3 E=4 F=5 G=6 H=7 I=8 K=9 L=10 M=11 (5 Replies)
Discussion started by: cdfd123
5 Replies

9. Shell Programming and Scripting

Lay person needs perl help solving error message

Hi, My name is Tex I am past 60 and in need of perl help. My hobby is genealogy and I am using a perl program to display my data on my web pages. I don't even know enough to know how to ask in the right way for the help I need. This program is written in perl it is open and has been updated... (2 Replies)
Discussion started by: tex
2 Replies

10. Solaris

how can obtain other user commands on the same server.

hi buddies, i want to learn something,so that we have several users on a sun server and via telnet, we are connecting to server same username and password root/something as root and after connection i want to see what other roots or users are doing on the server, i want to see their command.... (2 Replies)
Discussion started by: nibiru78
2 Replies
Login or Register to Ask a Question