insert text at every end of the line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting insert text at every end of the line
# 1  
Old 05-12-2009
insert text at every end of the line

Hi,
I just wanted to know if you have any idea or script to insert a text at everyend of the line, the text will vary. for example

sample:
this is line1 ok
this is line2 ok
this is line3 ok

output:

this is line1 ok /home/line1.txt
this is line2 ok /home/line2.txt
this is line3 ok /home/line3.txt

thanks
# 2  
Old 05-12-2009
you have posted previously on shell scripting issues. by now you should already know how to do it as its very simple and its a very common task. If you have issues, check the top of this thread at the "More UNIX and Linux Forum Topics You Might Find Helpful" box. there are similar threads regarding your issue. try your best.
# 3  
Old 05-12-2009
for i in `cat file|awk '{print $3}' hostss`; do sed "s/$/ $i.txt/g" file; done

it doesnt work, and i have checked the topics above,none was relevant to mine Smilie
# 4  
Old 05-12-2009
Quote:
Originally Posted by invinzin21
for i in `cat file|awk '{print $3}' hostss`; do sed "s/$/ $i.txt/g" file; done

it doesnt work, and i have checked the topics above,none was relevant to mine Smilie
a lot of redundancy is used in the above code. standard way of doing is simply go through the file with a loop, and echoing/printing out the original line plus the next text
Code:
while read line
do
  # echo the line and the new text.
done < file

other ways include using sed and substituting $ for the new text, which you have already done above, but no need to cat and awk the file.

if you want to use awk, its the same concept, you can either use gsub() to substitute the newline, or just print the record out plus the new text
# 5  
Old 05-12-2009
sorry ghost but i cant realyy get it, im not really a programmer im a sysad Smilie i jsut wanted to make my work so easy..

sample:
this is line1 y
this is line2 y
this is line3 y

output:
this is line1 y > /home/aa/line1.txt
this is line2 y > /home/aa/line2.txt
this is line3 y> /home/aa/line13txt
# 6  
Old 05-12-2009
while read i
do
a=$(echo $i|awk '{print $2}')
echo $(echo $i $a.txt)
done < a


got it
# 7  
Old 05-12-2009
Code:
sed 's/\(\<.*\>\) \(\<.*\>\) \(\<.*\>\) \(\<.*\>\)/\1 \2 \3 \4 \/home\/\3\.txt/' a.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Insert a line of text on nth line of a file

Hi All, I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise My intention is to insert a line of text after 13th line of every file inside a particular directory. While trying to do it for a single file , i am using sed sed '3 i this is the 4th line' filename sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies

2. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

3. UNIX for Dummies Questions & Answers

Insert a line in a text file

I want to insert a line with text after the 9th line of a text file. How would I do this using sed or awk? (2 Replies)
Discussion started by: lost.identity
2 Replies

4. UNIX for Dummies Questions & Answers

insert string at end of line if it found from list

Hi all, can some one help me out file 1 i have 06/01 3:14 d378299 06/01 8:10 d642036 06/01 10:51 d600441 06/01 10:52 d600441 06/01 11:11 d607339 06/01 11:49 d398706 something like this and in file named list i have ( there is space btwn 06/01 and 11:49 and d398706) d607339... (5 Replies)
Discussion started by: zozoo
5 Replies

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

6. Shell Programming and Scripting

gawk (dos) insert backslash at end of line

I have created with the DOS-command dir a list of a directory. Directory of C:\Users\User\Documents 09.06.2011 20:50 48.322 file1.txt 02.11.2010 23:00 9.216 file2.txt 15.12.2010 21:06 26.793 file2.txt Now i would like to add the directory ahead of the filename. Therefore a... (6 Replies)
Discussion started by: sdf
6 Replies

7. UNIX for Dummies Questions & Answers

insert period at the end of each line

file1 contains: this is a test this is a test and only a test this is another test this is another test and only another only i'd like my file to look like this: this is a test. this is a test and only a test. this is another test. this is another test and only another only. (6 Replies)
Discussion started by: tjmannonline
6 Replies

8. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

9. Shell Programming and Scripting

Insert two strings at the beginning and at the end of each line of a file

Hi, excuse me for my poor english. My problem is that: I have a File i want to add to each line of that file two strings: one at the beginning of the line, one at the ending. string1="abcd" string2="efgh" i want $string1 content $string2 for each line. Is that possible? (3 Replies)
Discussion started by: Linux-fueled
3 Replies

10. Shell Programming and Scripting

Insert a line in a text file

So I need to write lines into line X of file X. I can get the file by doing: cfgnumber=$(cat -n -comm.cfg| grep -i "servicegroup_name 24x7-comunicacions") echo $cfgnumber it outputs the Line where it finds now I need to start writing something right bellow that line. thanks (10 Replies)
Discussion started by: 4scriptmoni
10 Replies
Login or Register to Ask a Question