awk or sed script to remove strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk or sed script to remove strings
# 1  
Old 10-25-2012
awk or sed script to remove strings

Below am trying to separate FA-7A:1, In output file it should display 7A 1

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
Command am using
Quote:
cat input_file.txt | 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 format:
22B7 10000000c9720873   0
22B7 10000000c95d5d8b   0
22BB 10000000c97843a2   0
22BB 10000000c975adbd   0

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

# 2  
Old 10-25-2012
Code:
perl -alne '{if(/^\d/) {$val=$F[0];$F[3]=~s/.*?-(\w+):(\d)/$1 $2/;print "$F[0] $F[1] $F[3]";} else{ if(/^100/){$F[2]=~s/.*?-(\w+):(\d)/$1 $2/;print "$val $F[0] $F[2]";next;}}}'

I thought this command in your previous post had helped you..
This User Gave Thanks to msabhi For This Post:
# 3  
Old 10-25-2012
Could you please show real input, and your exact desired output. It looks like you have a lot of code you do not need, but we cannot tell.

Telling us what it does wrong helps no one.
# 4  
Old 10-25-2012
Hope this is much clear, After removing unwanted lines from file below is the input, I need the below Red values also in Output with space between 7D 0
Code:
3EFC    10000000c97239cf  FIBRE  FA7D:0
        10000000c96fc9f1  FIBRE  FA10D:0
 
3EFD    10000000c97239cf  FIBRE  FA7D:0
        10000000c96fc9f1  FIBRE  FA10D:0
 
3EFE    10000000c97239cf  FIBRE  FA7D:0
        10000000c96fc9f1  FIBRE  FA10D:0

Quote:
Script am using is:
cat Input_file.txt_nw_B | awk '/^ *$/{next;} length($1)!=4 { $0=l " " $0; } {l=$1 ; gsub("[:-]"," "); $3=$4="";} 1'
Code:
Output am getting:
3EFC 10000000c97239cf   0
3EFC 10000000c96fc9f1   0
3EFD 10000000c97239cf   0
3EFD 10000000c96fc9f1   0
3EFE 10000000c97239cf   0
3EFE 10000000c96fc9f1   0


Last edited by aix_admin_007; 10-25-2012 at 05:57 PM..
# 5  
Old 10-25-2012
using infile:
Code:
3EFC    10000000c97239cf  FIBRE  FA7D:0
        10000000c96fc9f1  FIBRE  FA10D:0
3EFD    10000000c97239cf  FIBRE  FA7D:0
        10000000c96fc9f1  FIBRE  FA10D:0
3EFE    10000000c97239cf  FIBRE  FA7D:0
        10000000c96fc9f1  FIBRE  FA10D:0

and:
Code:
awk '/^ *$/{next;} length($1)!=4 { $0=l " " $0; } {l=$1 ; gsub("[:-]"," "); $3=""; sub("^FA","",$4)} 1' infile

output:
Code:
3EFC 10000000c97239cf  7D 0
3EFC 10000000c96fc9f1  10D 0
3EFD 10000000c97239cf  7D 0
3EFD 10000000c96fc9f1  10D 0
3EFE 10000000c97239cf  7D 0
3EFE 10000000c96fc9f1  10D 0

This User Gave Thanks to rdrtx1 For This Post:
# 6  
Old 10-25-2012
rdrtx1,

Thanks a Lot. Gives exact required output.

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to remove field and match strings to add text

In file1 field $18 is removed.... column header is "Otherinfo", then each line in file1 is used to search file2 for a match. When a match is found the last four strings in file2 are copied to file1. Maybe: cut -f1-17 file1 and then match each line to file2 file1 Chr Start End ... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

How to remove certain character strings with awk?

Hi all, I need to remove DBPATH= and /db from the string below using awk (or sed, as it also exists on the machine). Input: DBPATH=/some/path/database/db Desired output: /some/path/database Thank you! (8 Replies)
Discussion started by: ejianu
8 Replies

3. Shell Programming and Scripting

USING sed to remove multiple strings/words from a line

Hi I use sed comnand to remove occurance of one workd from a line. However I need to removed occurance of dufferent words in ne line. Original-1 Hi this is the END of my begining Comand sed s/"END"/"start"/g Output-1 Hi this is the start of my beginig But I have more... (9 Replies)
Discussion started by: mnassiri
9 Replies

4. Shell Programming and Scripting

Need the script to remove common strings,tags etc

I have a file say "example.xml" and the contents of this example.xml are <project name="platform/packages/wallpapers/Basic" path="packages/wallpapers/Basic" revision="225e410f054c4ad5c828b0fec9be1b47c4376711"/> <project name="platform/packages/wallpapers/Galaxy4"... (3 Replies)
Discussion started by: acdc
3 Replies

5. Shell Programming and Scripting

any savant ? using AWK/SED to remove newline character between two strings : conditional removal

I'd like to remove (do a pattern or precise replacement - this I can handle in SED using Regex ) ---AFTER THE 1ST Occurrence ( i.e. on the 2nd occurrence - from the 2nd to fourth occurance ) of a specific string : type 1 -- After the 1st occurrence of 1 string1 till the 1st occurrence of... (4 Replies)
Discussion started by: sieger007
4 Replies

6. Shell Programming and Scripting

Sed: Remove whitespace between two strings

I have a 13 number string, some whitespace, and then /mp3. I need to join them. Everyline that I need this for begins with "cd" (without the quotes). What it looks like now: cd media/Audio/WAVE/9781933976334 /mp3 What I want my output to be: cd media/Audio/WAVE/9781933976334/mp3 The 13... (7 Replies)
Discussion started by: glev2005
7 Replies

7. Shell Programming and Scripting

Remove strings within range using sed

Hey folks I have a big file that contains junk data between the tags <point> and </point> and I need to delete it (including `<point>' and `</point>'). i.e. a = 1 <point> 123123 2342352 234231 234256 </point> print a needs to become a = 1 print a I'm certain that this is a... (10 Replies)
Discussion started by: ksk
10 Replies

8. Shell Programming and Scripting

sed: remove characters between and including 2 strings

I have the following line: 4/23/2010 0:00:38.000: Copying $$3MSYDDC02$I would like to use sed (or similiar) to remove everthing between and including $ that appears in the line so it ends up like this. 4/23/2010 0:00:38.000: Copying 3MSYDDC02I have been trying these but i'm really just... (5 Replies)
Discussion started by: jelloir
5 Replies

9. Shell Programming and Scripting

Replace Strings with sed or awk

Hello i need some help with the usage of sed. Situation : 2 textfiles, file.in , file.out In the first textfile which is called file.in are the words for the substitution. Every word is in a new-line like : Firstsub Secondsub Thridsub ... In the second textflie wich is called file.out is... (5 Replies)
Discussion started by: Kingbruce
5 Replies

10. Shell Programming and Scripting

Sed or awk script to remove text / or perform calculations from large CSV files

I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)
Discussion started by: metronomadic
6 Replies
Login or Register to Ask a Question