sed append in first column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed append in first column
# 1  
Old 09-01-2009
sed append in first column

hi,

anyone can give a sample command on sed. the text file date list belows;

test.txt

Code:
"a","bbb",123
"b","ccc",234
"c","eee",456

output i need to add these word "xxx"


Code:
"xxx","a","bbb",123
"xxx","b","ccc",234
"xxx" ,"c","eee",456

thanks in advance,
FSP

Last edited by Don Cragun; 09-20-2016 at 04:35 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 09-01-2009
using awk..
Code:
-bash-3.2$ cat list3
"a","bbb",123
"b","ccc",234
"c","eee",456
-bash-3.2$ awk '{print "\"xxx\"",$0}' list3
"xxx" "a","bbb",123
"xxx" "b","ccc",234
"xxx" "c","eee",456
-bash-3.2$

sed..

Code:
-bash-3.2$ sed 's/^/"xxx",&/g' list3
"xxx","a","bbb",123
"xxx","b","ccc",234
"xxx","c","eee",456
-bash-3.2$


Last edited by ryandegreat25; 09-01-2009 at 07:37 AM..
# 3  
Old 09-01-2009
ryandegreat25,

fantastic, it work.

regards,
fsp
# 4  
Old 09-01-2009
And if you were editing the file with vi, you could use
Code:
:%s/.*/"xxx",&/

If you created a file, call it ex.cmds, like this
Code:
:%s/.*/"xxx",&/
:x

then you could alter your file with
Code:
ex test.txt < ex.cmds

# 5  
Old 09-01-2009
many many thanks for the input
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

2. Shell Programming and Scripting

awk script to append suffix to column when column has duplicated values

Please help me to get required output for both scenario 1 and scenario 2 and need separate code for both scenario 1 and scenario 2 Scenario 1 i need to do below changes only when column1 is CR and column3 has duplicates rows/values. This inputfile can contain 100 of this duplicated rows of... (1 Reply)
Discussion started by: as7951
1 Replies

3. Shell Programming and Scripting

awk to Sum columns when other column has duplicates and append one column value to another with Care

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (1 Reply)
Discussion started by: as7951
1 Replies

4. Shell Programming and Scripting

Matching column value from 2 different file using awk and append value from different column

Hi, I have 2 csv files. a.csv HUAWEI,20LMG011_DEKET_1296_RTN-980_IDU-1-11-ISV3-1(to LAMONGAN_M),East_Java,20LMG011_DEKET_1296_RTN-980_IDU-1,20LMG011,20LMG 027_1287_LAMONGAN_RTN980_IDU1,20LMG027,1+1(HSB),195.675,20LMG011-20LMG027,99.9995,202.6952012... (7 Replies)
Discussion started by: tententen
7 Replies

5. Shell Programming and Scripting

How to append the output in a new column?

input1 john 20 bob 30 input2 john 60 bob 100 cat input1 >> output cat input2 >> output ouput john 20 bob 30 john 60 bob 100 desired output input1 input1 input2 input2 john 20 john 60 (3 Replies)
Discussion started by: quincyjones
3 Replies

6. Shell Programming and Scripting

Matching column then append to existing File as new column

Good evening I have the below requirements, as I am not an experts in Linux/Unix and am looking for your ideas how I can do this. I have file called file1 and file2. I need to get the second column which is text1_random_alphabets and find that in file 2, if it's exists then print the 3rd... (4 Replies)
Discussion started by: mychbears
4 Replies

7. Shell Programming and Scripting

Append column using awk/nawk

Is there any way I can achieve this? Considering test1 : a 1 2 3 4 b 2 3 4 5 c 12 1232 14 1 d 10 13 4 5 e 1 5 6 9 1 And test to be some string : qw twe tew we qw I want something like this : a 1 2 qw 4 b 2 3 twe 5 (5 Replies)
Discussion started by: aksijain
5 Replies

8. UNIX for Dummies Questions & Answers

append a column by concatenating other columns

Hi In a tab delimited file how can I add a column that have values concatenated from all columns. For example input.txt test1 test2 test3 zz2 mm uu pp3 yy kk ss2 tt ll zz3 mm uu pp23 yy kk ss3 tt ll 11e 22 44 33c 22 99 output.txt test1 test2 test3 reslt (6 Replies)
Discussion started by: mary271
6 Replies

9. Shell Programming and Scripting

Append a new column in a file

Hi all, I need to append 'ls --' command output as a new column in a existing file. for example, when i do ls -- i will get the below, aaa_import.csv bbb_import.csv ccc_import.csv ddd_import.csv ffff_import.csv i need to cut the aaa, bbb, ccc, ddd and append this a new column... (5 Replies)
Discussion started by: baskivs
5 Replies

10. Shell Programming and Scripting

Append the data to first column

Hi, The below is the content of the file. 008.03.50.21|ID4|0015a3f01cf3 008.04.20.16|ID3|0015a3f02337 008.04.20.17|ID4_1xVoice|00131180d80e 008.04.20.03|ID3_1xVoice|0015a3694125 008.04.30.05|ID3_1xVoice|0015a3f038af 008.06.30.17|ID3_1xVoice|00159660d454... (2 Replies)
Discussion started by: ravi_rn
2 Replies
Login or Register to Ask a Question