Looking for a short way to summarise many sed commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Looking for a short way to summarise many sed commands
# 1  
Old 06-16-2011
Looking for a short way to summarise many sed commands

Hello,

I have a large number of sed commands that I execute one after the other, simply because I don't know if there's a shorter way to do it. I hope someone can help me save some time :-)

These are my commands:

1.) remove all " in the file:
Code:
    sed -e 's/\"//g' file

2.) insert ( and space at the beginning of each line:
Code:
    sed 's/^/( /' file

3.) insert " ) at the end of each line:
Code:
     sed 's/$/\" )/' file

4.) insert blizzard_ at position 9:
Code:
    sed 's/./blizzard_/9' file

5.) insert space and " at position 22:
Code:
     sed 's/./ \"/22' file

6.) delete 5th and 6th character in each line:
Code:
     sed 's/^\(.\{5\}\).\(.*\)/\1\2/' file
     sed 's/^\(.\{6\}\).\(.*\)/\1\2/' file

Thanks a lot in advance,

Kat

Last edited by Scott; 06-16-2011 at 06:02 PM.. Reason: Code tags, please...
# 2  
Old 06-16-2011
You could try stringing them all together with semi-colons?

Code:
sed "s/.../.../g;s/.../.../" file

# 3  
Old 06-16-2011
Basically you have three options:

1) Use the semi-colon separator:
Code:
sed 'command1;command2;...;commandn' input_file

2) Use the "-e" option:
Code:
sed -e 'command1' -e 'command2' ... -e 'commandn' input_file

3) Use the file command option:
Code:
sed -f Sed_File input_file

Where "Sed_File" will look like this:
Code:
command1
command2
...
commandn

This User Gave Thanks to Shell_Life For This Post:
# 4  
Old 06-16-2011
Thanks a lot! I will try those out :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort and summarise between patterns

Hi! I have a text file which I would like to sort, summarise and count between the pattern "--Current Database" This is my text file: -- Current Database: `city` New York Chicago Las Vegas San Francisco -- Current Database: `country` United States Mexico Portugal Mexico Mexico... (9 Replies)
Discussion started by: mac-arrow
9 Replies

2. UNIX for Beginners Questions & Answers

Simplifying awk/sed short pipeline

I have a file like this: FileName,Well,Sample Description,Size ,Calibrated Conc. ,Assigned Conc. ,Peak Molarity ,Area,% Integrated Area,Peak Comment,Observations 2017-11-15 - 13.49.50.D1000,EL1,Electronic Ladder,25,5.22,,321,0.803,,,Lower Marker 2017-11-15 - 13.49.50.D1000,EL1,Electronic... (6 Replies)
Discussion started by: Xterra
6 Replies

3. Shell Programming and Scripting

Nested sed commands

Hi, I get the following response by gphoto2 and I would like to substract the index number of the current item. In this case 3. gphoto2 --get-config /main/imgsettings/iso Label: ISO Speed Type: RADIO Current: 200 Choice: 0 100 Choice: 1 125 Choice: 2 160 Choice: 3 200 Choice: 4 250 ..... (11 Replies)
Discussion started by: Nic2015
11 Replies

4. Shell Programming and Scripting

Grouping sed commands

Hello, would you please help me with why my SED command file is outputting the entire input file instead of only the text that I'm trying to block? cat testfile O 111111111-00 DUE-DATE METHOD: FREQUENCY: O 222222222-00 DUE-DATE METHOD: FREQUENCY: O 333333333-02 DUE-DATE METHOD:... (4 Replies)
Discussion started by: lneedh1
4 Replies

5. Shell Programming and Scripting

merging sed commands

Hi, I've a shell that uses two sed commands to tailor a file. sed 's/ */ /g' | sed 's/%/%%/g' Is it possible to merge this in to a single sed? Thanks! (2 Replies)
Discussion started by: dvah
2 Replies

6. Shell Programming and Scripting

Running sed commands

Hello I need to run some sed commands but it involves "/" in the substitute or delete, any ideas how I get round the problem. Example: cat file1.txt | sed -e '/</Header>/d' > file2.txt This errors due to the forward slash before the Header text. Thanks (3 Replies)
Discussion started by: Dolph
3 Replies

7. Shell Programming and Scripting

Using variables in sed commands

Hi there, I need to be able to put the hostid of my box into a file (replacing the text "enter_hostid_here" so i tried sed -e 's/enter_hostid_here/`hostid`/g' inputfile > outputfile but it takes the `hostid` literally as text .....how can I get this info into the file (ideally in a single... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

8. UNIX for Dummies Questions & Answers

combining sed commands

I would like to change the lines: originalline1 originalline2 to: originalline1new originalline1newline originalline2new originalline2newline To do this, id like to combine the commands: sed 's/^/&new/g' file > newfile1 and sed '/^/ a\\ newline\\ \\ (2 Replies)
Discussion started by: Dave724001
2 Replies

9. Shell Programming and Scripting

multiple sed commands

hello! I have a few sed commands sed '/^$/d' < $1 > tmp.t sed '/^ \{3,\}/d' < tmp.t > tmp1.txt ..... how can I write them in a single line? sed '/^$/d' < $1 > | '/^ \{3,\}/d' < $1 > tmp1.txt any idea? thanks. (5 Replies)
Discussion started by: george_
5 Replies

10. Shell Programming and Scripting

sed commands

I have a configuration file that when a certain script runs in updates. I want to use sed and can't seem to get the syntax right. A line from the configuration file looks like: DATE=20040909 12:00:10 When the script is run I want to change the date and time, i.e. removing the previous... (7 Replies)
Discussion started by: dbrundrett
7 Replies
Login or Register to Ask a Question