Hi Team,
I m getting my script commands output like given below
[ U-UU-YRYT-NOD-6002 ] GETA-TILL-INF;
U-UU-YRYT-NOD-6002 2015-05-14 THU 19:44:10
C2221 RETRIEVE TILL INFORMATION : COMPLD
----------------------------------------------------------------------
CONNECT_CARD_ID CONNECT_PORT_ID DDE_ID ANT_ID_INSTALL_ID TILT
----------------------------------------------------------------------
0 0 0 1 75
0 1 0 1 65
0 2 0 1 25
----------------------------------------------------------------------
COUNT = 3
;
I need to convert this output in csv like given below..
U-UU-YRYT-NOD-6002 75
U-UU-YRYT-NOD-6002 65
U-UU-YRYT-NOD-6002 25
I m using follwing script but not working
cmd_sys NOD_$y GETA-TILL-INF | grep "-" | awk -F' ' '{print$1}' | head -2 | tail -1 > /home/lotus/lotus/temp1.txt
cmd_sys NOD_$y GETA-TILL-INF | head -3 | tail -3 | awk -F' ' '{print$2}' >> /home/lotus/output/temp1.txt
RudiC
May 15, 2015, 4:08am
2
Please use code tags, NOT ICODE tags!
You haven't given any rule on how to select a) the prefix b) the data/data lines. Making wild assumptions, this will give the desired result for EXACTLY the sample input given:
cmd_sys NOD_$y GETA-TILL-INF | awk '/[^-]-[^-]/ {PR=$1} NF==5 && $NF+0==$NF {print PR, $NF}'
U-UU-YRYT-NOD-6002 75
U-UU-YRYT-NOD-6002 65
U-UU-YRYT-NOD-6002 25
1 Like
Another option
awk 'NR==3{s=$1} NR==8{p=1} /--/{p=0} p{print s, $NF}' file
It Working.....
but output come like..
U-UU-YRYT-NOD-6002 75 U-UU-YRYT-NOD-6002 65 U-UU-YRYT-NOD-6002 25
---------- Post updated at 03:45 AM ---------- Previous update was at 03:39 AM ----------
Hi Scrutinizer,
awk 'NR==3{s=$1} NR==8{p=1} /--/{p=0} p{print s, $NF}'
this gives output
TILT
TILT
TILT
TILT
TILT
TILT
TILT
TILT
RudiC
May 15, 2015, 4:56am
5
Please use code tags, NOT ICODE tags!
It came out correctly for me. So I presume you have something in your input sample that you did not post in here. Post the output of od -ctx1
[akshay@localhost tmp]$ cat infile
[ U-UU-YRYT-NOD-6002 ] GETA-TILL-INF;
U-UU-YRYT-NOD-6002 2015-05-14 THU 19:44:10
C2221 RETRIEVE TILL INFORMATION : COMPLD
----------------------------------------------------------------------
CONNECT_CARD_ID CONNECT_PORT_ID DDE_ID ANT_ID_INSTALL_ID TILT
----------------------------------------------------------------------
0 0 0 1 75
0 1 0 1 65
0 2 0 1 25
----------------------------------------------------------------------
COUNT = 3
;
[akshay@localhost tmp]$ awk '/[^-]-[^-].*:/{s = $1; next } NF==5 && $1~/[0-9]+/{print s,$NF}' infile
U-UU-YRYT-NOD-6002 75
U-UU-YRYT-NOD-6002 65
U-UU-YRYT-NOD-6002 25
1 Like
[..]
---------- Post updated at 03:45 AM ---------- Previous update was at 03:39 AM ----------
Hi Scrutinizer,
awk 'NR==3{s=$1} NR==8{p=1} /--/{p=0} p{print s, $NF}'
this gives output
TILT
TILT
TILT
TILT
TILT
TILT
TILT
TILT
No I mean directly, without using heads and tails..
cmd_sys NOD_$y GETA-TILL-INF | awk 'NR==3{s=$1} NR==8{p=1} /--/{p=0} p{print s, $NF}'
1 Like
Hi Akshay , Thanks
Sorry But i need "CONNECT_PORT_ID" also
Plz help
0 U-UU-YRYT-NOD-6002 75
1 U-UU-YRYT-NOD-6002 65
2 U-UU-YRYT-NOD-6002 25
Try this
awk '/[^-]-[^-].*:/{s = $1; next } NF==5 && $1~/[0-9]+/{print $2,s,$NF}' infile
1 Like