how to use multiple files in sed with w command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to use multiple files in sed with w command
# 1  
Old 12-26-2008
how to use multiple files in sed with w command

i have a command like :
sed -n 's/^[0-9]*[02468] /&/w even' <file
if i want to write to multiple files like
sed -n 's/^[0-9]*[02468] /&/w zero two three' < file
its not working it is taking "zero two three" as a single file i want to write to 3 seperate files . pls can anyone help me
# 2  
Old 12-26-2008
Hi,

try:

Code:
sed -n -e '/file1/w f1' -e '/file1/w f2' file

HTH Chris
# 3  
Old 12-27-2008
Code:
sed -n 's/^[0-9]*[02468] /&/p' file | tee zero two > three

Though that is the same as:

Code:
sed -n '/^[0-9]*[02468] /p' file | tee zero two > three

Or:

Code:
grep '^[0-9]*[02468] ' file | tee zero two > three

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

I have 4000 files like $cat clus_grp_seq10_g.phy 18 1002 anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG aver_OOF92921_1 ... (1 Reply)
Discussion started by: sammy777888
1 Replies

2. Shell Programming and Scripting

sed Command on Multiple Files and retaining the same file name

Hi All I am trying to run sed command to remove first 2 charcaters from a file on Multiple Files in my directory and what to retain the same file name . I want to know how to retain the same file name but with changes . Can some one please let me know how to proceed with this . ... (7 Replies)
Discussion started by: honey26
7 Replies

3. Shell Programming and Scripting

Multiple sed in one command

Hi, How do I run multiple sed on a file similar to the below in one command? I can't global substitute the 401 as it can occur elsewhere in the row and needs to be maintained if it does. sed "s/,40128/,128/" test2.csv > test3.csv sed "s/,40192/,192/" test3.csv > test4.csv sed ... (6 Replies)
Discussion started by: ksexton
6 Replies

4. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

5. Shell Programming and Scripting

SED command using multiple input files

What is the syntax to use multiple input files in a SED command. i.e. substitute a word with a phrase in every file in a directory. for every file in /usr/include that has the word "date" in the file grep -l '\<date\>' /usr/include/*.h find each occurrence of the word "time" in the file &... (3 Replies)
Discussion started by: sheoguey
3 Replies

6. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

7. UNIX for Dummies Questions & Answers

SED on multiple files

Hello all, Search & replace works fine using sed on a single file. Ex: sed -i 's/day/night/g' test1.sh There are many *.sh files in my current directory that I would like use sed on. I tried running the sed command using wild card but it did not work. sed -i 's/day/night/g' *.sh ... (7 Replies)
Discussion started by: luft
7 Replies

8. UNIX for Dummies Questions & Answers

sed on multiple files?

Hi, I want to do a search and replace on multiple text files. Can I use sed to do this? i.e. I want to do something like: $ sed *.html -e 's/<\/body>/<\!-- blah -->\n<\/body>/' | grep -1 body ... then pipe/ channel the results back into the same files that were searched. how would... (2 Replies)
Discussion started by: mgrahamnz
2 Replies

9. Shell Programming and Scripting

Can we give multiple patterns to a sed command???

HI, I want to know can multiple pattern be given inside a sed statement.. Input: aa_bb_cc.Mar-22-2007 cc_dd_ee.Mar-21-2007 aa_1002985_952.xml aa_bb_032207.txt aa_bb_cc_10002878.dat Output: aa_bb_cc cc_dd_ee aa.xml aa_bb.txt aa_bb_cc.dat (6 Replies)
Discussion started by: kumarsaravana_s
6 Replies

10. UNIX for Dummies Questions & Answers

sed across multiple files

I've got a bunch of files (40 or so) and in each there is a substitution I need to perform. I execuet the following sed command but it just make the changes to the screen without affecting the original file. sed "s/, LA/,LA/g" * (All files in the directory need this update). So I tried... (4 Replies)
Discussion started by: peter.herlihy
4 Replies
Login or Register to Ask a Question