How to change this file with SED?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to change this file with SED?
# 1  
Old 12-30-2005
How to change this file with SED?

I have a file like below:
Quote:
AA: 1
AB: kkkkkkkkk
BC: LLLLLLLLL
CD: PPPPPPP
EF: OOOOOO
TY: (((((((((
OL: HHHHHHH

AA: 2
AB: 111111111
BC: 222222222
CD: 333333333
EF: 444444444
TY: (((((((((((
OL: 555555555

AA: 3
AB: 66666666
BC: 77777777
CD: 88888888
EF: 99999999
TY: ((((656(((((
OL: ########
I want to delete the rows which begining with "BC" "CD" and "TY" .
then change every fields into one row like this

Quote:
AA: 1 AB: kkkkkkkkk EF: OOOOOO OL: HHHHHHH
AA: 2 AB: 111111111 EF: 444444444 OL: 555555555
AA: 3 AB: 66666666 EF: 99999999 OL: ########
at last delete the head words :
Quote:
1 kkkkkkkkk OOOOOO HHHHHHH
2 111111111 444444444 555555555
3 66666666 99999999 ########
USing awk to change it is not hard.
I want to know how to do this work using SED ?
Thank you!
BEST REGARDS Smilie

Last edited by bejgirl; 12-30-2005 at 08:09 AM..
# 2  
Old 12-30-2005
try this

sed -e '/^BC/d' -e '/^CD/d' -e '/^TY/d' datafilename|sed 'N;N;N;N; s/\n/ /g'|sed 's/\([A-Z][A-Z]:\)//g'
# 3  
Old 12-30-2005
ranj@chn Thank you! It works!
But i want to know how to do it with SED 1 LINE,do not use pipe.
Cheers
# 4  
Old 01-03-2006
not quite sure

Not sure about that. May some one else could help. I am also just learning sed.
Regards,
Ranjith
# 5  
Old 01-03-2006
How about this ? I have re-arranged your requirements and then made the sed statement.

Code:
sh-2.05b$ sed -e '/AA/{N;N;N;N;N;N;s_\n_ _g;s_\(BC:.*\) \(EF:\)_\2_g;s_\(TY:.*\) \(OL:\)_\2_g;s_..: __g}' input.txt     
1 kkkkkkkkk OOOOOO HHHHHHH

2 111111111 444444444 555555555

3 66666666 99999999 ########

Vino
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using sed to change file into an awk script

Hi I want to use sed to change a text files input into an awk script. For example if the input says " chord -- english " I want to change this using sed 's/pattern 1 /pattern 2 /'g filename but I don't understand how to use part of the pattern 1 to input that into pattern 2 . Like after... (10 Replies)
Discussion started by: enforcer
10 Replies

2. UNIX for Beginners Questions & Answers

File name change with sed

I have a bunch of text files like this: Sample_S1_L001_R1.txt Sample_S10_L001_R1.txt Sample_S11_L001_R1.txt I am using the following script to add a 0 to those files with a single digit after the S: ls *.txt | sed 's/\(.*_S\)\(_.*\)/mv & \10\2/' | sh And then the following script to... (4 Replies)
Discussion started by: Xterra
4 Replies

3. Shell Programming and Scripting

sed command not working for me to change text in a file

UNIX gurus I need your help with the following (The server is an AIX box). I have a text file with the following information: ******************************************************** SOME LINES case :WORD1 SOME LINES :WORD2 SOME LINES :WORD3 SOME LINES esac SOME LINES... (7 Replies)
Discussion started by: curiousmal
7 Replies

4. Shell Programming and Scripting

Datestamp format 2nd change in csv file (awk or sed)

I have a csv file formatted like this: 2014-08-21 18:06:26,A,B,12345,123,C,1232,26/08/14 18:07and I'm trying to change it to MM/DD/YYYY HH:MM for both occurances. I have got this: awk -F, 'NR <=1 {print;next}{"date +%d/%m/%Y\" \"%H:%m -d\""$1 "\""| getline dte;$1=dte}1' OFS="," test.csvThis... (6 Replies)
Discussion started by: say170
6 Replies

5. Shell Programming and Scripting

Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines

I have a bunch of file numbers in the file 'test': I'm trying the above command to change all the instances of "H" to "Na+" in the file testsds.pdb at the line numbers indicated in the file 'test'. I've tried the following and various similar alternatives but nothing is working: cat test |... (3 Replies)
Discussion started by: crunchgargoyle
3 Replies

6. Shell Programming and Scripting

sed substitution or awk, need to direct change the file

I want change the file when the line contains $(AA) but NOT contains $(BB), then change $(AA) to $(AA) $(BB) eg: $(AA) something $(AA) $(BB) something (7 Replies)
Discussion started by: yanglei_fage
7 Replies

7. Shell Programming and Scripting

Creating a sed script to change ip addresses in a file

So I'm new to this sed command and I am trying to create a script that replaces ip addresses when I name a file but can't tweak it to work. Here is what it looks like: #!/bin/bash # file=$1 # sed -e 's/-CPUaddr 10.30.10.166/-CPUaddr 10.30.10.151/g' -i "$file" sed -e 's/-CPUaddr... (10 Replies)
Discussion started by: uradunce
10 Replies

8. UNIX for Dummies Questions & Answers

sed question - change 2d to last line in file

The file is repeating blocks of text separated by a blank line. Some of the lines are unique. e.g.: This is unique line This is line 2 This is line 3 This is line 4 This is unique line This is line 2 This is line 3 This is line 4 ... The goal is to change/replace line 4... (2 Replies)
Discussion started by: uiop44
2 Replies

9. Shell Programming and Scripting

sed to change a configuration file

Hi I want to create a configuration file from a template one. The only thing to change for now is the port number that I need to take from another file that has this format: server:port So I need to take the 2nd field. server is passed in the script argument. how to do that? I... (1 Reply)
Discussion started by: melanie_pfefer
1 Replies

10. Shell Programming and Scripting

how to change a number in a file with sed?

Hello, I have a file which contains some line as follows, 9.9 TEMP 9.9 MUCOEFF 0.0 EPSILON And I want to increase this MUCOEFF by 0.2 as 9.9 TEMP 10.1 MUCOEFF 0.0 ... (7 Replies)
Discussion started by: lorenzz
7 Replies
Login or Register to Ask a Question