How to use sed to put string end of line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to use sed to put string end of line?
# 1  
Old 10-18-2011
How to use sed to put string end of line?

I have several file as below, and i want to put .txt to specific text contain ^main=EXE^cmd=run script /usr/prog/bd_,

file1
Code:
7.9102 12.1528 16.3672 7.4002
^main=EXE^cmd=run script /usr/prog/bd_123^"
line 16.3672 7.3134 17.8711 6.0981

file 2
Code:
7.9102 12.1528 16.3672 7.4002 
^main=EXE^cmd=run script /usr/prog/bd_148^"
5.6836 17.5998 19.3566 15.5998

file 3
Code:
1.10001
^main=EXE^cmd=run script /usr/prog/bd_165^"
1.10001.888.20.3


I want my output file

file1
Code:
7.9102 12.1528 16.3672 7.4002
^main=EXE^cmd=run script /usr/prog/bd_123.txt^"
line 16.3672 7.3134 17.8711 6.0981

file 2
Code:
7.9102 12.1528 16.3672 7.4002 
^main=EXE^cmd=run script /usr/prog/bd_148.txt^"
5.6836 17.5998 19.3566 15.5998

file 3
Code:
1.10001
^main=EXE^cmd=run script /usr/prog/bd_165.txt^"
1.10001.888.20.3


Last edited by Franklin52; 10-19-2011 at 04:01 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 10-18-2011
I saw the same topic already, looks like a homework.
# 3  
Old 10-18-2011
please help me

---------- Post updated at 09:53 PM ---------- Previous update was at 09:52 PM ----------

Quote:
Originally Posted by rdcwayx
I saw the same topic already, looks like a homework.
please help me
# 4  
Old 10-19-2011
sed

Hi,
Try this one,
Code:
sed 's/$/addstr/g' file

Cheers,
Ranga:-)
# 5  
Old 10-19-2011
Quote:
Originally Posted by rangarasan
Hi,
Try this one,
Code:
sed 's/$/addstr/g' file

Cheers,
Ranga:-)
thanks for help but using this code will put .txt all of the end of line..i want to put the .txt in the specific line
# 6  
Old 10-19-2011
awk

Hi,

you can use awk to match the pattern and add the string at the end of line,

Code:
awk 'BEGIN{OFS="";}$0 !~ /pattern/{print;}$0 ~ /pattern/{print $0,"addstr";}' input_file

here,
1. pattern must be same in two regex.
2. addstr - going to append in the end of line.

Cheers,
RangaSmilie
# 7  
Old 10-19-2011
See if this sed fills your requirement
Code:
"s#\^main=EXE\^cmd=run script /usr/prog/[Aa-Zz]\{1,5\}_[0-9]\{1,5\}#&.txt#g" file > outfile

It will match a line containing <first part> /usr/prog<any 1 to 5 letters> followed by an underscore and <any 1 to 5 numbers >.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

How to add a new string at the end of line by searching a string on the same line?

Hi, I have a file which is an extract of jil codes of all autosys jobs in our server. Sample jil code: ************************** permission:gx,wx date_conditions:yes days_of_week:all start_times:"05:00" condition: notrunning(appDev#box#ProductLoad)... (1 Reply)
Discussion started by: raghavendra
1 Replies

2. Shell Programming and Scripting

Put three points at the end of a line

Hello I have a file like this Anyway, if you are sincere in finding the druid Alcuin then you're going to need ships. die with the faith that you have stood shield to shield with your brothers. To honour, to glory, to a valiant death and then on to the hall of heroes. Skal! ... (6 Replies)
Discussion started by: thailand
6 Replies

3. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

4. Shell Programming and Scripting

sed - Find a String and append a text end of the Line

Hi, I have a File, which have multiple rows. Like below 123456 Test1 FNAME JRW#$% PB MO Approver XXXXXX. YYYY 123457 Test2 FNAME JRW#$% PB MO Super XXXXXX. YYYY 123458 Test3 FNAME JRW#$% PB MO Approver XXXXXX. YYYY I want to search a line which contains PB MO Approver and append... (2 Replies)
Discussion started by: java2006
2 Replies

5. Shell Programming and Scripting

Using sed to put text end of line

how to use sed to put .txt end of line..my input file below file1 make=^bak12^". DEV=LONG^cmd/usr/bak/ade4^" ..................................... file 2 make=^and_LONG/bak12^". DEV=LONG^cmd/usr/bak/ban3^" .......................................... file 3... (6 Replies)
Discussion started by: zulabc
6 Replies

6. Shell Programming and Scripting

Remove line based on string and put new line with parameter

Hi Folks, I am new to ksh, i have informatica parameter file that i need to update everyday with shell script. i need your help updating this file with new parameters. sample data $$TABLE1_DATE=04-27-2011 $$TABLE2_DATE=04-23-2011 $$TABLE3_DATE=03-19-2011 .......Highligned... (4 Replies)
Discussion started by: victor369
4 Replies

7. Shell Programming and Scripting

put string end of the line

I've a problem to put .h end of the line..below my input file fg_a bb fg_b bb fg_c bb fg_d aa fg_f ee and i want the output file as below fg_a.h bb fg_b.h bb fg_c.h bb fg_d.h (6 Replies)
Discussion started by: zulabc
6 Replies

8. Shell Programming and Scripting

to put date at the end of each line

#!/bin/ksh if test -f file6.txt then rm file6.txt fi a=`date +"%F"` awk '{print $0,"$a"}' file3.txt > file6.txt ----------------------------------------------------------------- i need to append date at the end of each line in file 3 and o/p it to file6.txt (3 Replies)
Discussion started by: ali560045
3 Replies

9. Shell Programming and Scripting

put each word in new line - sed or tr

Hello ! I have a result of ls command in a file: file1 file2 file3.out file4.pdf file5 they all are separated by space. I need to put them on a separate line example: file1 file2 file3.out file4.pdf fil35 i tried sed 's/ /\n/g' inputfile > outputfile but did not help (3 Replies)
Discussion started by: hemangjani
3 Replies

10. Shell Programming and Scripting

put a semicolon at the end of each line of a file

hi, Consider there is a file containing 200 lines. please let me know which command is to be used to put a semicolon at the end of each line. if no single command is there then how it can be achieved. (1 Reply)
Discussion started by: surjyap
1 Replies
Login or Register to Ask a Question