The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Parsing String, Search then display rows buddyme UNIX for Advanced & Expert Users 9 04-27-2008 04:43 AM
How to append a Value to all the rows in a file dsshishya Shell Programming and Scripting 2 03-20-2008 05:04 PM
append a string to a grep result melanie_pfefer Shell Programming and Scripting 8 03-19-2008 07:19 AM
Need to append file name to all rows in in .csv file Satyagiri Shell Programming and Scripting 3 10-13-2006 02:32 AM
append esc string beilstwh Shell Programming and Scripting 2 05-11-2005 01:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-30-2006
Rock Rock is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 23
Append string in all rows

I would like to append a string at the end of each row of a .dat file.
please give me some advice? Thanks.

e.g.
#content in abc.dat
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
...


#after running the script/command, "bbbbbbbbbb" will be appended as follow.
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbb
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbb
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbb
...
  #2 (permalink)  
Old 11-30-2006
spoodie's Avatar
spoodie spoodie is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 14
It is just me or does this look like an exam question?
  #3 (permalink)  
Old 12-01-2006
Rock Rock is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 23
I have writen a simple script to arhieve my purpose. However, "There is not enough memory available now" is prompted. Can my script be optimized to reduce resource? Thanks.

append_string=`cat ${source_file} | awk ' BEGIN { FS = "\n" } { if ($1 ~ "SWIFT5" ) {print $1, " :: SEND = N :: SEV = 0 :: ERROR = 11414 :: COMP = Name :: "
} else {print $1;} }'`
  #4 (permalink)  
Old 12-01-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Here is a sed solution.

Code:
str="string to be attached"
sed -e "s/.*/&$str/g" input.txt
  #5 (permalink)  
Old 12-01-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
A Python alternative
Code:
#!/usr/bin/python
string_to_attach = "a string to attach"
for line in open("yourfile"):
    line = line.strip()
    print "%s%s" %( line, string_to_attach )
prompt:
Code:
# python test.py > outfile
  #6 (permalink)  
Old 12-01-2006
Rock Rock is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 23
For the sed solution,


The Pattern is constructed with a variable string inside a text.
e.g.
aaa123aaa
aaa4 5aaa
aaa678aaa

sed -e "s/aaa*aaa/&$str/g" ${source_file}

Why I can't use "*" to find the pattern?
  #7 (permalink)  
Old 12-01-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by Rock
For the sed solution,


The Pattern is constructed with a variable string inside a text.
e.g.
aaa123aaa
aaa4 5aaa
aaa678aaa

sed -e "s/aaa*aaa/&$str/g" ${source_file}

Why I can't use "*" to find the pattern?
I didnt quite get what you are looking for.

str should contain the string you want to append.

Does this help ?


Code:
sed -e "s/aaa.*aaa/&$str/g" ${source_file}
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0