Replace the file using sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace the file using sed
# 1  
Old 01-14-2008
Replace the file using sed

I have file with 70 lines.

I want to add 'SLV' at the starting of the line if the line has first character as 0 or 1 or 2 or ..9

Nothing else has to be changed in the file. Please anyone advice.
# 2  
Old 01-14-2008
Code:
sed -e "s/^\([0123456789]\)/SLV \1/g" file.txt

# 3  
Old 01-14-2008
shell
Code:
#!/bin/sh
while IFS= read -r line
do
 case $line in 
   [0-9]* ) printf "%s\n" "SLV $line";;
    *) printf "%s\n" "$line";;
 esac
done < "file" > newfile

# 4  
Old 01-14-2008
Code:
sed 's/^[0-9]/SLV &/' file.txt

# 5  
Old 01-14-2008
using Perl:
Code:
perl -pi -e 's/^(\d)/SLV \1/' file

# 6  
Old 11-20-2008
Check with this

Quote:
Originally Posted by senthil_is
I have file with 70 lines.

I want to add 'SLV' at the starting of the line if the line has first character as 0 or 1 or 2 or ..9

Nothing else has to be changed in the file. Please anyone advice.
=======================================================

#!/usr/bin/ksh

ls -l |grep .txt|nawk '{print $9}' > list

while read FILE

do

perl -pi -e 's/01/09\/SWV/g' $FILE

done <list
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using sed to replace inside file

How can I change the comma sign (,) to plus sign (+) with the sed command or any regex? I mean to change only the comma that beteen the quotation marks. From this file: A,B,C A,"B,C",D "A,B",C,D A,B,"C,D" To this file: A,B,C A,"B+C",D "A+B",C,D A,B,"C+D" (6 Replies)
Discussion started by: elior
6 Replies

2. Shell Programming and Scripting

Loop through file and replace with sed

Hello all, I need some help please. I got file1 with names. foo bar foo bar foo bar foo bar foo bar and I got file2 with some text some text some text #KEYWORD some text some text some text (3 Replies)
Discussion started by: stinkefisch
3 Replies

3. Shell Programming and Scripting

Sed, replace variables in file

Hi Everyone, I need some help with sed and I'm totally new to it. I have a template file with variables in it. These variables start with a '$' sign and are exactly one character long (plus the '$' sign). For example: $a, $b, etc. Each variable should be replaced with the contents of a... (9 Replies)
Discussion started by: csarli2006
9 Replies

4. UNIX for Dummies Questions & Answers

Using sed to replace / in text file

Hi, I want to use sed to replace " /// " with "///" in a text file. However I am getting error messages when I use sed 's/ /// /////g' input.txt > output.txt. How do I go about doing this in sed? Input: 219518_s_at 0.000189 ELL3 / SERINC4 Output: 219518_s_at 0.000189 ELL3/SERINC4 (5 Replies)
Discussion started by: evelibertine
5 Replies

5. Shell Programming and Scripting

How to replace a string containing @ in a file using sed ?

I have a list of names and email addresses. Sample File - username=poga--poga@yahoo.com new-york,US 512834 username=poga123--poga123@hotmail.com new-jersey,US 0894753 Requirement is to replace the email ids as dummy_username@xyz.com using sed only. Output File -... (4 Replies)
Discussion started by: poga
4 Replies

6. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

7. Shell Programming and Scripting

How to use sed to replace the a string in the same file using sed?

How do i replace a string using sed into the same file without creating a intermediate file? (7 Replies)
Discussion started by: gomes1333
7 Replies

8. Shell Programming and Scripting

SED to replace file content

Hi, I want to replace _F* by _F in a xml file. what is the sed command. I have tried sed "s/_F$/_F/g" or sed "s/_F*/_F/g" , but it does not work. thx file content <TAG>KC_FOU</TAG> <TAG>KC_FABC</TAG> <TAG>KC_FABCDG</TAG> desire output <TAG>KC_F</TAG> <TAG>KC_F</TAG> <TAG>KC_F</TAG> (6 Replies)
Discussion started by: godfreyyip
6 Replies

9. UNIX for Dummies Questions & Answers

sed replace words in file and keep some

lets see if i can explain this in a good way. im trying to replace some words in a file but i need to know what the words are that is beeing replaced. not sure if sed can do this. file.name.something.1DATA01.something.whatever sed "s/./.DATA?????/g" need to know what the first . is... (2 Replies)
Discussion started by: cas
2 Replies

10. Shell Programming and Scripting

Replace a line in a file with sed

Hi, I am trying to write a script that will replace "PermitEmptyPasswords yes" with "PermitEmptyPasswords no". The following does not seem to work: - sed 's!/"PermitEmptyPasswords yes"/!/"PermitEmptyPasswords no"/!' Appreciate any ideas. Thanks (2 Replies)
Discussion started by: mtech3
2 Replies
Login or Register to Ask a Question