Need to sort an output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to sort an output
# 1  
Old 10-07-2015
Bug Need to sort an output

with a command i get a long list (example) and the entrys are intended.

Code:
 
      DName=AAAAA
          DName=AAAAA
          lba=838,860,800
              label=ftw_1
      DName=BBBBB
          DName=BBBBB
          lba=838,860,800
              label=ftw_2
      DName=CCCCC
          DName=CCCCC
          lba=838,860,800
              label=ftw_3

That list is arround 1000 lines and come from an CLI request. One "Block" is from DName to "label"
I CANT supress that double "DName". What i need is
Code:
AAAAA;838,860,800;ftw_1

Since two hours i play around but i cant get it to work as i like or what i need. My sed skills are to small.

Last edited by zaxxon; 10-08-2015 at 03:40 AM.. Reason: more code tags
# 2  
Old 10-07-2015
Please show next time first with what code you have tried so far.

Code:
$ awk -F\= '/DName=/ {a=$2} /lba=/ {b=$2} /label=/ {print a OFS b OFS $2}' OFS=\; infile
AAAAA;838,860,800;ftw_1
BBBBB;838,860,800;ftw_2
CCCCC;838,860,800;ftw_3

# 3  
Old 10-07-2015
Hello Serano,

Following may help you in same.
Code:
awk '/DName/{sub(/.*=/,X,$0);A=$0;getline;if($0 ~ /DName/){getline};if($0 ~ /lba=/){sub(/.*=/,X,$0);A=A ";"$0;getline};if($0 ~ /label/){sub(/.*=/,X,$0);A=A ";" $0};print A;A=""}'  Input_file

Output will be as follows.
Code:
AAAAA;838,860,800;ftw_1
BBBBB;838,860,800;ftw_2
CCCCC;838,860,800;ftw_3

Now above code is considering that your Input_file is always having a sequence in which first string DName, then next line has string DName=, then then next line has string lba=, followed by string label= in next line.

Thanks,
R. Singh
# 4  
Old 10-12-2015
Big Thx Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Any way to sort ps output based on STIME?

Hi, This is one of the thing that am looking for when I post the question on the ps wrapper. It has since been closed as it has taken me too long to post an example. I have replaced some of the original content of the ps output. uname -a = SunOS <hostname> 5.11 11.3 sun4v sparc sun4v ... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. UNIX for Dummies Questions & Answers

Ls output sort on multiple column

Hi All, I have one requirement, where I need to have output of ls -l command sorted on 1) first on filename 2) last modified time ( descending ) - latest change first. I am not able to figure out how to do it.. Also I dont have a way to change Date display for ls -ltr command.. I am... (5 Replies)
Discussion started by: freakabhi
5 Replies

3. Shell Programming and Scripting

sort ps output in seconds

Now I van sort in hour-minute-second. I need in seconds ps -eo pid,etime,args --sort=start_time | grep bash Sample Output 15064 03:23 -bash I need in 03:23 in seconds (1 Reply)
Discussion started by: anil510
1 Replies

4. Shell Programming and Scripting

Sort and output to different files

Hi all! I have a comma delimited file and I'm sorting it based on fields 6, 8 and 10. The following does the job: sort -t, -nk6,10 unsorted.txt -o sorted.txt What I need to do now is to write every row containing same values on fields 6, 8 and 10 to a different file. Any ideas on how to do... (2 Replies)
Discussion started by: Tr0cken
2 Replies

5. Shell Programming and Scripting

Sort output is different with Corn

Hi, I am sorting a file, but getting different output with crontab. input file-file z Z x X y Y when I sort manually sort file x X y Y z Z (4 Replies)
Discussion started by: suresh3566
4 Replies

6. UNIX for Dummies Questions & Answers

Sort fdupes output by size

Hi I have a file that is a fdupes output. I'd like to sort the duplicated file by size. The format file is the following: 5996544 bytes each: /path1/to/file1.jpg /path2/to/file1.jpg /pathx/to/file1.jpg ... random number of lines /path999/to/file1.jpg 591910 bytes each:... (2 Replies)
Discussion started by: AdminLew
2 Replies

7. UNIX for Dummies Questions & Answers

How to sort output from find from oldest to newest?

Hi, How do I sort the output of find to provide a listing of files from oldest to newest? For example, if I do a find /tmp -type f -print I want the output to be sorted in the order of the oldest to the newest file. Thanks in advance. (2 Replies)
Discussion started by: newbie_01
2 Replies

8. Shell Programming and Scripting

sort output

this one is a bit tricky: host16 /etc/passwd changed Thu Jan 3 16:39:48 host3 /etc/group changed Thu Jan 3 16:39:48 host2 /etc/services changed Thu Jan 3 16:39:48 host10 /etc/group changed Thu Jan 10 09:59:01 host11 /etc/group changed Thu Jan 3 18:55:38 host17 /etc/group changed Thu Jan... (9 Replies)
Discussion started by: funksen
9 Replies

9. UNIX for Dummies Questions & Answers

how to sort and arrange an output

ok so I have a list of names that end in either ot,om,oa. So for example DETOT MANOA DET0M DET0A MANOT SEAOT etc... I want to be able to group this list by OT, OM, OA and have the output have some headers like this and be alphabatized and if possible be in colums instead of like... (10 Replies)
Discussion started by: llsmr777
10 Replies

10. UNIX for Dummies Questions & Answers

Sort - only one field appears in output?

I'm running against a file with 1008 records like this, all beginning '4760 Slave': 4760 Slave,7,3607 ,GL ,200605,11320024 , ,GBP ,X00033 ,AI80190 ... (1 Reply)
Discussion started by: miwinter
1 Replies
Login or Register to Ask a Question