How to concatenate a string in every row data of a file??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to concatenate a string in every row data of a file??
# 1  
Old 12-13-2008
How to concatenate a string in every row data of a file??

Please look into the example.
My source file is like,

00,57,3,2008-07-24 06:30:06
10,1,8025171,"1M00",17907023,2008-07-23 18:16:58
10,2,8025171,"1M00",17907023,2008-07-23 18:17:01
99,184

What should i do if i want output like...

hello,00,57,3,2008-07-24 06:30:06
hello,10,1,8025171,"1M00",17907023,2008-07-23 18:16:58
hello,10,2,8025171,"1M00",17907023,2008-07-23 18:17:01
hello,99,184
# 2  
Old 12-13-2008
u can use sed..

sed 's/^/hello,/g' filename
# 3  
Old 12-13-2008
Quote:
Originally Posted by npatwardhan
u can use sed..

sed 's/^/hello,/g' filename
The "g" option is unnecesary since there's just one replacement per line.

Regards
# 4  
Old 12-13-2008
thats right, thanks for pointing it out.
# 5  
Old 12-14-2008
Quote:
Originally Posted by npatwardhan
thats right, thanks for pointing it out.
Hi, What u wrote is right for the specific case. May be My question was not very clear But in this problem scenario "hello" is coming from a varriable say temp. The content of temp varriable may change every time when I process the script.
In the above code we can not pass the varriabe. I mean we cann't write
sed 's/^/$temp,/g' filename
If we write like this it will give output
$temp,00,57,3,2008-07-24 06:30:06
$temp,10,1,8025171,"1M00",17907023,2008-07-23 18:16:58
$temp,10,2,8025171,"1M00",17907023,2008-07-23 18:17:01
$temp,99,184

So, The resultant question is "How to pass a varriable in the above sed command?".
# 6  
Old 12-14-2008
Quote:
Originally Posted by Franklin52
The "g" option is unnecesary since there's just one replacement per line.

Regards
Hi, What u wrote is right for the specific case. May be My question was not very clear But in this problem scenario "hello" is coming from a varriable say temp. The content of temp varriable may change every time when I process the script.
In the above code we can not pass the varriabe. I mean we cann't write
sed 's/^/$temp,/g' filename
If we write like this it will give output
$temp,00,57,3,2008-07-24 06:30:06
$temp,10,1,8025171,"1M00",17907023,2008-07-23 18:16:58
$temp,10,2,8025171,"1M00",17907023,2008-07-23 18:17:01
$temp,99,184

So, The resultant question is "How to pass a varriable in the above sed command?".
# 7  
Old 12-14-2008
Use double quotes, single quotes prevent the expanding of variables.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. Emergency UNIX and Linux Support

[Solved] Mysql - Take data from row and copy it to another row

Sorry if I repost my question in this section, but I'm really in a hurry since I have to finish my work... :( Dear community, I have a table with two rows like: Row1 Row2 ======= ======= 7,3 text 1 1,3 text 2 1,2,3 blabla What i need to do is add/copy... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

3. Programming

Concatenate string from text file

Hi mY files paths are defined as : //sbase = 'D:\data\sample_AMC\fasta_files\'; sbase2 = 'D:\data\sample_AMC\fasta_files\results\'; snameprefix = 'orig_ind'; snameprefix3 = 'results_ind'; ... const string filname = sbase + snameprefix + snamesuffix; const string resultsname_ =... (2 Replies)
Discussion started by: siya@
2 Replies

4. Shell Programming and Scripting

Append data to new row in CSV file every day

Hi All I will run the same script every day in corn and output should go to same CSV file but in different row with dates on it. Below is my example in attached format. Script i am using to collect switch port online DATE=`date '+%d-%m-%y'` for f in `cat... (1 Reply)
Discussion started by: ranjancom2000
1 Replies

5. Shell Programming and Scripting

Search for string in a file, extract two another strings and concatenate to a variable

I have a file with <suit:run date="Trump Tue 06/19/2012 11:41 AM EDT" machine="garg-ln" build="19921" level="beta" release="6.1.5" os="Linux"> Need to find word "build" then extract build number, which is 19921 also release number, which is 6.1.5 then concatenate them to one variable as... (6 Replies)
Discussion started by: garg
6 Replies

6. UNIX for Dummies Questions & Answers

Concatenate column data, grouped by row info

Hello, I have data which looks like: 1 2 3 a x 0 0 a 0 p 0 a 0 0 0 b 0 b c b a 0 0 b 0 0 0 c q 0 s c 0 r 0 I would like to concatenate each of the column data, grouped by the row values, i.e. my... (4 Replies)
Discussion started by: Gussifinknottle
4 Replies

7. Shell Programming and Scripting

Problem in writing the data to a file in one row

Hi All I am reading data from the database and writing to temporary file in the below format. 1=XP|external_component|com.adp.meetingalertemail.processing.MeetingAlertEmail|EMAILALERTPUSH|32|4#XP |classpath|/usr/home/dfusr/lib/xalan.jar: /usr/home/dfusr/lib/xerces.jar: ... (2 Replies)
Discussion started by: rajeshorpu
2 Replies

8. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

9. Shell Programming and Scripting

Concatenate 2 rows into 1 row

I need to search a file for two values (valueA & valueB). ValueA will be on a different row than valueB, and concatenate the two together on the same row of my output. Example: search input file for strings "node" and "OS", combine the two results into one row input node A text text OS... (4 Replies)
Discussion started by: indianadoug
4 Replies
Login or Register to Ask a Question