Appending the first word of each line to the end of each line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending the first word of each line to the end of each line
# 1  
Old 03-18-2010
Appending the first word of each line to the end of each line

Hi Experts,

Am relatively new to shell programming so would appreciate some help in this regard.
I am looking at reading from a file, line by line, picking the first word of each line and appending it to the end of the line.

Any suggestions?

INPUT FILE -
Code:
3735051 : 10gdb_nonfa_noldapsync_ps2 : http://dte.com/dte30/faces/monitorPage/jobId=
3735052 : 11gdb_nonfa_noldapsync_ps2 : http://dte.com/dte30/faces/monitorPage/jobId=
3735053 : 112gdb_nonfa_noldapsync_ps2 : http://dte.com/dte30/faces/monitorPage/jobId=

This is how id like my output file to look like -
Code:
3735051 : 10gdb_nonfa_noldapsync_ps2 : http://dte.com/dte30/faces/monitorPage/jobId=3735051
3735052 : 11gdb_nonfa_noldapsync_ps2 : http://dte.com/dte30/faces/monitorPage/jobId=3735052
3735053 : 112gdb_nonfa_noldapsync_ps2 : http://dte.com/dte30/faces/monitorPage/jobId=3735053

TIA

Last edited by zaxxon; 03-18-2010 at 11:56 AM.. Reason: use code tags pleasy, ty
# 2  
Old 03-18-2010
Use code tags next time please. If not sure what I am talking about, leave me a note.

To your problem:
Code:
awk '{print $0$1}' infile

# 3  
Old 03-18-2010
This works well, thanks !!
My bad about the code tags, will keep in mind in future !
# 4  
Old 03-18-2010
And yet another -

Code:
perl -lane 'print $_,$F[0]' yourfile

tyler_durden
# 5  
Old 03-18-2010
... and another Smilie
Code:
sed 's/^\([^ ]*\).*/&\1/' file

Cheers,
Alister
# 6  
Old 03-18-2010
Code:
awk '$0=$0$1' urfile

# 7  
Old 03-23-2010
Code:
sed 's/\(.[^:]*\)\(.*\)/\1\2\1/' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to append word at end of line

hello Team, I am looking for sed command or script which will append word at end of line. for example. I want to validate particular filesystem with mount |<filesystem name> command. if nodev parameter is not there then it should add in the fstab file with receptive to the filesystem. # mount... (8 Replies)
Discussion started by: ghpradeep
8 Replies

2. UNIX for Dummies Questions & Answers

Appending | (pipe) to end of each line which does not have it

I have a text file in which all records end with pipe character and newline, but a few do not have a pipe at the end. Something like this 1|John|32|US| 2|Matt|35|UK 3|Rex|36|EU| So in the above example the second line does not have a pipe at the end My requirement is to append a... (5 Replies)
Discussion started by: abhilashnair
5 Replies

3. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

4. UNIX for Dummies Questions & Answers

Appending Date at the end ONLY in first line of file

Hi, My requirement is to append a date in format DDMMYYYYHHMISS at the end of first line of file which is HEADER. I am trying command sed -i '1s/.*/&<date_format>/' <file_name> Where <date_format>=`date +%m%d%Y%H%M%S` I am somehow misisng the right quotes ti get this added in above... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

5. Shell Programming and Scripting

Appending a word to the last line

Hi, I would like to append input given id at last line of file. For ex: In the following sample.txt file i would like to append the input given user id (after id6,id7) but it is adding on the next line instead same line. Sample.txt read=id1,id2,id3 write=id4,id5,id6 Thanks Raveendran (8 Replies)
Discussion started by: raveendran.l
8 Replies

6. Shell Programming and Scripting

appending a blank line for a group of files at the end

hi, i m having a group of files starting with name 'Itemdelete<timestamp>' . my requirment is to append a blank line at the end of files ,using unix in all the Itemdelete* files with a single unix command without using scripts.can any body put some light to this requiremnt. regards Angel (4 Replies)
Discussion started by: angel12345
4 Replies

7. Shell Programming and Scripting

Appending data to the end of a line

I have searched the forms and I can not find info on appending each line of one file to the same line of another file. I know that I can cat one file to another or append the 2nd file to the end of the 1st but not quite sure how to append one line of data to another. For example File 1 has ... (2 Replies)
Discussion started by: scw132
2 Replies

8. Shell Programming and Scripting

Sed : identify a pattern and append a word at the end of a line

Hello to all, On aix, I want to identify a term on a line in a file and then add a word at the end of the line identified. I do not want the word to be added when the line contains the symbol "#". I use the following command, but it deletes the term identified then adds the word. #sed... (4 Replies)
Discussion started by: dantares
4 Replies

9. Shell Programming and Scripting

appending a line to the end of several hundred files

I have a bunch of files named publish.php within subdirs. I need to append a line at the end of each file. I thought I could do it with find and echo like this: find . -name publish.php -exec echo "<? include('path/to/file.php'); ?>" >> '{}' \; but that appends the line to a file named {}... (2 Replies)
Discussion started by: surroscape
2 Replies

10. Shell Programming and Scripting

Add a word at the end of each line in a file

Hi I want to read a flat file and add a word/value at the end of each line in the file and store the output in a temporary file. How can i do this? Plz help me with this. Regards, Saurabh (6 Replies)
Discussion started by: bhalotias
6 Replies
Login or Register to Ask a Question