Want to sort a file using awk & sed to get required output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to sort a file using awk & sed to get required output
# 8  
Old 10-25-2012
What happens if sed is changed to:
Code:
sed 's/-/ /g'

?
# 9  
Old 10-25-2012
Quote:
Originally Posted by rdrtx1
What happens if sed is changed to:
Code:
sed 's/-/ /g'

?
Quote:
Input file:
Symmetrix ID : 0001901
Device Identifier Type Dir:P
------ ---------------- ----- ----------------
08F7 10000000c9502ee3 FIBRE FA-7A:1
10000000c94f912a FIBRE FA-10A:1
10000000c97239cf FIBRE FA-7B:0
10000000c96fc9f1 FIBRE FA-10B:0
Symmetrix ID : 0001901
Device Identifier Type Dir:P
------ ---------------- ----- ----------------
39D1 10000000c9502ee3 FIBRE FA-7D:0
10000000c94f912a FIBRE FA-10D:0
Quote:
| grep -v Device | grep -v Symmetrix | sed 's/-/ /g' | awk '/^ *$/{next;} length($1)!=4 { $0=l " " $0; } {l=$1 ; gsub("[:-]"," "); $3=$4="";} 1'

Code:
Gives same output as below:
22B7 10000000c9720873   0
22B7 10000000c95d5d8b   0
22BB 10000000c97843a2   0
22BB 10000000c975adbd   0

Code:
Not showing FA ports as required output:
 
01FB 10000000c97843a2   8C  0
01FB 10000000c96fb279   9C  0
22AF 10000000c97843a2   8C  0
22AF 10000000c975adbd   8C  0

# 10  
Old 10-26-2012
try this..

Code:
grep -v -E "Device|Symmetrix|^------" A.txt | awk -F "FIBRE FA-|:| " '/FIBRE/{if($0 !~ /^1000/){s=$1;$1=$1}else{$1=s" "$1}}1' | sort

# 11  
Old 10-26-2012
Try:
Code:
awk -F" |-|:"  'NF==6  {tmp=$1}
                /FIBRE/ {print tmp,$(NF-4),$(NF-1),$NF}
               ' file
01FB 10000000c97843a2 8C 0
01FB 10000000c96fb279 9C 0
22AF 10000000c97843a2 8C 0
22AF 10000000c975adbd 8C 0
22AF 10000000c96fb279 9C 0
22AF 10000000c9720873 9C 0
22AF 10000000c95d5d8b 9C 0

You might need to use another awk version on your system; see posts in this forum.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Move & Sort by Name - Kick out Bad File Names & More

I have a dilemma, we have users who are copying files to "directory 1." These images have file names which include the year it was taken. I need to put together a script to do the following: Examine the file naming convention, ensuring it's the proper format (e.g. test-1983_filename-123.tif)... (8 Replies)
Discussion started by: Nvizn
8 Replies

2. Shell Programming and Scripting

Replacing FQDN by hostnames in a CSV file with sed & awk

Hello, Beginning with shell scipting, I'm trying to find in a csv file, the lines where the field related to hostname is displayed as an FQDN intead the hostname. (some lines are correct) and the to correct that inside the file: Novell,11.0,UNIX Server,bscpsiws02,TxffnX1tX1HiDoyBerrzWA==... (2 Replies)
Discussion started by: Wonto
2 Replies

3. Shell Programming and Scripting

awk help: Match data fields from 2 files & output results from both into 1 file

I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6. Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies

4. UNIX for Advanced & Expert Users

Using awk or sed need the output in the new file

Please find the input file as given below: 2012/02/29 11:00:00~~CRITICAL~For customer 00000476 no daily files were found in the 010137933 account directory. 2012/02/29 11:00:00~~CRITICAL~For customer 05006802 no daily files were found in the 010115166 account directory. 2012/02/29... (0 Replies)
Discussion started by: av_sagar
0 Replies

5. Shell Programming and Scripting

Sort a the file & refine data column & row format

cat file1.txt field1 "user1": field2:"data-cde" field3:"data-pqr" field4:"data-mno" field1 "user1": field2:"data-dcb" field3:"data-mxz" field4:"data-zul" field1 "user2": field2:"data-cqz" field3:"data-xoq" field4:"data-pos" Now i need to have the date like below. i have just... (7 Replies)
Discussion started by: ckaramsetty
7 Replies

6. Shell Programming and Scripting

Awk & sed query for output

Hello, I have a file. its content are like below. mdn:87439842 imsi:23082038203 Ctime:12082010 01:20:10 mdn:9324783783 imsi:402349823322 Ctime: 12072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime: 23072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime:18072010 01:20:10 mdn:87439842... (3 Replies)
Discussion started by: Sanket11
3 Replies

7. Shell Programming and Scripting

SED/AWK file read & manipulation

I have large number of data files, close to 300 files, lets say all files are same kind and have extension .dat , each file have mulitple lines in it. There is a unique line in each file containing string 'SERVER'. Right after this line there is another line which contain a string 'DIGIT=0',... (4 Replies)
Discussion started by: sal_tx
4 Replies

8. Shell Programming and Scripting

Problem to add the string(without sed & awk) into the middle of file

Hi, I have tried many times to add the string into the first line of the file or the middle of the file but could not find the solution. I first tried by $echo "paki" >> file This code only append paki string at the end of file "file" but how can i add this "paki" into the first line or... (5 Replies)
Discussion started by: ali hussain
5 Replies

9. Shell Programming and Scripting

sed & awk--get section of file based 2 params

I need to get a section of a file based on 2 params. I want the part of the file between param 1 & 2. I have tried a bunch of ways and just can't seem to get it right. Can someone please help me out.....its much appreciated. Here is what I have found that looks like what I want....but doesn't... (12 Replies)
Discussion started by: Andy Cook
12 Replies
Login or Register to Ask a Question