Need to fetch only selected data in CSV


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to fetch only selected data in CSV
# 1  
Old 05-15-2015
Need to fetch only selected data in CSV

Hi Team,
I m getting my script commands output like given below


Code:
[ 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..


Code:
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

Code:
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


Last edited by Scrutinizer; 05-15-2015 at 05:12 AM.. Reason: Changed ICODE tags to CODE tags
# 2  
Old 05-15-2015
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:
Code:
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

This User Gave Thanks to RudiC For This Post:
# 3  
Old 05-15-2015
Another option
Code:
awk 'NR==3{s=$1} NR==8{p=1} /--/{p=0} p{print s, $NF}' file

# 4  
Old 05-15-2015
It Working.....
but output come like..

Code:
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,

Code:
awk 'NR==3{s=$1} NR==8{p=1} /--/{p=0} p{print s, $NF}'

this gives output

Code:
TILT
TILT
TILT
TILT
TILT
TILT
TILT
TILT


Last edited by rbatte1; 05-15-2015 at 06:28 AM.. Reason: ICODE -> CODE tags
# 5  
Old 05-15-2015
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
# 6  
Old 05-15-2015
Code:
[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
;

Code:
[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

This User Gave Thanks to Akshay Hegde For This Post:
# 7  
Old 05-15-2015
Quote:
Originally Posted by Ganesh Mankar
[..]
---------- Post updated at 03:45 AM ---------- Previous update was at 03:39 AM ----------

Hi Scrutinizer,

Code:
awk 'NR==3{s=$1} NR==8{p=1} /--/{p=0} p{print s, $NF}'

this gives output

Code:
TILT
TILT
TILT
TILT
TILT
TILT
TILT
TILT

No I mean directly, without using heads and tails..

Code:
cmd_sys NOD_$y GETA-TILL-INF | awk 'NR==3{s=$1} NR==8{p=1} /--/{p=0} p{print s, $NF}'

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. UNIX for Beginners Questions & Answers

Shell script to fetch values in csv

I need to fetch below values from this file. (1 Reply)
Discussion started by: nit42
1 Replies

2. Shell Programming and Scripting

Fetch data from file

Hi, I am new to scripting. I have a log file and need to fetch specific logs and copy to another file. A copy of the log is like this: =============================================================== = JOB : server123#jobs1.jobstream1 = USER : andyc = Tue 08/01/17... (3 Replies)
Discussion started by: Prngp
3 Replies

3. UNIX for Beginners Questions & Answers

How to fetch specific data from a file.?

Hi , I have a file which contains 2 days logs(here it is 24 and 25) I want to list data only for date 25 fron the file. please suggest me how should i get this. file content mentioned below 17-05-24 Name Succ Fail 00:00:29 ... (5 Replies)
Discussion started by: scriptor
5 Replies

4. Shell Programming and Scripting

Help Need to fetch the required data

Hi Guys, Am in need of your help one more time on my real data. I have a file which contains more than thousand lines of data Live data shown for 4 iterations. We have more than thousand lines of data:- -------------------------------------------------------------------------- ... (4 Replies)
Discussion started by: rocky2013
4 Replies

5. UNIX for Dummies Questions & Answers

how to fetch data in unix

Hi All, I have a file with the below data as shown. A|2|20120430 B|EMP|NAME|DEPT C|12|SARC|01 C|23||ASDD|02 D|END OF FILE I want to fetch only the records that contains C|, what is unix command to fetch this data. Thanks (5 Replies)
Discussion started by: halpavan2
5 Replies

6. Shell Programming and Scripting

Fetch data between two dates from a file

Hi All, I m new to this forum & UNix too. currently i have a requirement which can fetch data from a logfile between two dates or timestamp. for example: 1. data from 2012 Jun to 2012 Jul 2. data from 2012 Jun to 2012 Jul 07 3. data from 2012 Jun 16 10:20 to 2012 Jul 03 10:10 Please... (7 Replies)
Discussion started by: KDMishra
7 Replies

7. Shell Programming and Scripting

Fetch data from a particular location

I want to fetch value from a particular location from a file but in each line in the file it appears at a different position so i tried using variable with cut command but it is not working properly. The code i have written is #!/bin/sh cat Sri1.log | while read d2 do grep -w... (9 Replies)
Discussion started by: Prachi Gupta
9 Replies

8. Shell Programming and Scripting

Fetch selected data from webpage

Hi All, Can anybody tell me the command used for extracting some selected lines from a web-page. I guess we'll have to do this using wget or Curl to achieve this.... If anbody has any idea abt it, kindly post your reply ASAP. Thanks. (1 Reply)
Discussion started by: sunnydynamic15
1 Replies

9. Shell Programming and Scripting

sorting csv file based on column selected

Hi all, in my csv file it'll look like this, and of course it may have more columns US to UK;abc-hq-jcl;multimedia UK to CN;def-ny-jkl;standard DE to DM;abc-ab-klm;critical FD to YM;la-yr-tym;standard HY to MC;la-yr-ytm;multimedia GT to KJ;def-ny-jrt;critical I would like to group... (4 Replies)
Discussion started by: tententen
4 Replies

10. Shell Programming and Scripting

csv content to call out selected function

Hi .. I am new to shell scripting I need to extract data from a csv file to call out selected function Sample contents of CSV PWR_JB, TB, Hk101, CB, Status,A PWR_JB, TB, HK101, OS, Status,B PWR_JB, 88V,SG201, OS, Status,B PWR_JB, TB, SG402, CB, Status,A PWR_JB, 88V,SG202,... (0 Replies)
Discussion started by: piresz
0 Replies
Login or Register to Ask a Question