Using sed to put text end of line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using sed to put text end of line
# 1  
Old 10-18-2011
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
....................................
DEV=LONG^cmd/usr/bak/13_2^"
...............................

file 4
...............................
DEV=LONG^cmd/usr/bak/14_2^"
..........................

i want my output file become
file 1
...........
DEV=LONG^cmd/usr/bak/ade4.txt^"
......................

file 2
.................................
DEV=LONG^cmd/usr/bak/ban3.txt^"
..................................

and so on

thanks

Last edited by zulabc; 10-18-2011 at 09:37 PM..
# 2  
Old 10-18-2011
Code:
echo 'DEV=LONG^cmd/usr/bak/ade4^"' | sed 's#..$#.txt&#'

# 3  
Old 10-18-2011
Hi zulabc,

Another way:
Code:
$ cat infile
DEV=LONG^cmd/usr/bak/ade4^"
DEV=LONG^cmd/usr/bak/ban3^"
DEV=LONG^cmd/usr/bak/13_2^"
DEV=LONG^cmd/usr/bak/14_2^"
$ sed 's/\(\^\)/.txt\1/2' infile
DEV=LONG^cmd/usr/bak/ade4.txt^"
DEV=LONG^cmd/usr/bak/ban3.txt^"
DEV=LONG^cmd/usr/bak/13_2.txt^"
DEV=LONG^cmd/usr/bak/14_2.txt^"

Regards,
Birei
# 4  
Old 10-18-2011
Hi,

Code:
echo 'DEV=LONG^cmd/usr/bak/ade4^"' | sed 's#..$#.txt&#'

I would like to know how this sed command will work?
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 10-18-2011 at 12:27 PM.. Reason: code tags, please!
# 5  
Old 10-18-2011
Quote:
Originally Posted by ravi_agarwalla
Hi,

Code:
echo 'DEV=LONG^cmd/usr/bak/ade4^"' | sed 's#..$#.txt&#'

I would like to know how this sed command will work?
take the last 2 characters and prepend them with ".txt".
# 6  
Old 10-18-2011
my fault actually my input file is in different file

file 1
.........
Code:
DEV=LONG^cmd/usr/bak/ade4^"

................

file 2
...................
Code:
DEV=LONG^cmd/usr/bak/ban3^"

......................

and so on

so i want my output file ending with .txt before ^"

Last edited by vgersh99; 10-18-2011 at 12:37 PM.. Reason: code tags, please
# 7  
Old 10-18-2011
Quote:
Originally Posted by zulabc
my fault actually my input file is in different file

file 1
.........
Code:
DEV=LONG^cmd/usr/bak/ade4^"

................

file 2
...................
Code:
DEV=LONG^cmd/usr/bak/ban3^"

......................

and so on

so i want my output file ending with .txt before ^"
doesn't the proposed solution work?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

4. Shell Programming and Scripting

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 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 7.9102 12.1528 16.3672 7.4002 ... (8 Replies)
Discussion started by: zulabc
8 Replies

5. 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

6. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

7. 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

8. 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

9. UNIX for Dummies Questions & Answers

using sed to append text to the end of each line

Anyone know how to use SED to append a comma to the end of each line example: field1,field2,field3,field4 If i Cat /textfile ---- How can i append the end of /textfile with a comman? (8 Replies)
Discussion started by: Redg
8 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