AWK adding prefix/suffix to list of strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK adding prefix/suffix to list of strings
# 1  
Old 04-18-2012
AWK adding prefix/suffix to list of strings

Code:
75
103
131
133
138
183
197
221
232
234
248
256
286
342
368
389
463
499
524
538
556
564

For this list of strings I would like to add a preifx, pdb_, and a suffix .namd
How might one do this for all records?
# 2  
Old 04-18-2012
Code:
 
awk '{print "pdb_"$0".namd"}' input.txt

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 04-18-2012
I would like to do these three printing commands at once, why am I getting an error?

Code:
awk '{print 'scp -r pdb_00.namd pdb_"$0".namd'; print 'sed 's/'pdb_00'/'pdb_"$0"'/g' pdb_"$0".namd > tempo'; print 'mv tempo pdb_"$0".namd'}' datA.dat > copy_script.bash

# 4  
Old 04-18-2012
can you tell, what exactly you want to do ?

scp all the files ?
# 5  
Old 04-18-2012
Ok, let's forget the last question, instead:
Code:
awk '{print "sed 's/pdb_00/'pdb_"$0"'/g' pdb_"$0".namd > tempo"}'

is there a way to preserve the sed 's///g' tick marks '
cause they disappear with the awk command?
# 6  
Old 04-18-2012
try with

Code:
 
\'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Prefix/Suffix on same file

Hi, I want to add prefix and suffix on line# 205 using SED or AWK and want to change on the same file without creating new file. This command will be used in the bash script Am using Bash shell Regards Nayaj (3 Replies)
Discussion started by: Nayaj
3 Replies

2. Shell Programming and Scripting

Suffix formatting with awk

i would like to format the 9 character with suffix as "0". i tried below it doesn't work. >a=12345 > echo $a | awk '{printf "%-09s\n",$1}' >12345 required output is 123450000 can you guys help me out ? (7 Replies)
Discussion started by: expert
7 Replies

3. Shell Programming and Scripting

Common prefix of a list of strings

Is there a simple way to find the longest common prefix of a space-separated list of strings, optionally by field? For example, given input: "aaa_b_cc aaa_b_cc_ddd aaa_b_cc aaa_b_cd"with no field separator, output: aaa_b_cwith _ field separator, output: aaa_bI have an awk solution which... (1 Reply)
Discussion started by: CarloM
1 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. Shell Programming and Scripting

Replace prefix and suffix of a string

Hi, I'm new about shell scripting, and I need to do something like abcd **1234** efgh by abcd '''1234''' efgh I know that command sed helps about change one string by another, but I dont know how to keep whatever is inside **_** and replace * with '. Thanks! (5 Replies)
Discussion started by: selvaya
5 Replies

6. Linux

Adding a prefix to a column using awk/sed commands

Hello, I am a newbie to linux and struggling to find a better way to append a column in a text file. Here is the file i want to modify: It has 8 columns (and thousands of rows). I want to append the first column by adding "chr" infront of the numbers. Some rows have a string in the first... (4 Replies)
Discussion started by: bjorngill
4 Replies

7. Shell Programming and Scripting

Adding prefix to the values in the script

Hi, test.txt contains below values 1 2 3 4 5 Desired output: 'TT.1', 'TT.2', 'TT.3', 'TT.4', 'TT.5' Last value should not contain the comma after the value. Below is the script which i have tried. I'm using Linux. #!/bin/bash for i in $test.txt (4 Replies)
Discussion started by: venkatesht
4 Replies

8. Shell Programming and Scripting

Adding new lines to a file + adding suffix to a pattern

I need some help with adding lines to file and substitute a pattern. Ok I have a file: #cat names.txt name: John Doe stationed: 1 name: Michael Sweets stationed: 41 . . . And would like to change it to: name: John Doe employed permanently stationed: 1-office (7 Replies)
Discussion started by: hemo21
7 Replies

9. Shell Programming and Scripting

Awk search for a element in the list of strings

Hi, how do I match a particular element in a list and replace it with blank? awk 'sub///' $FILE list="AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA,... (2 Replies)
Discussion started by: grossgermany
2 Replies

10. Shell Programming and Scripting

prefix suffix to each argument

Hi, I have a variable, which contains comma separated values. Something like. StringA="abc,def,ghi,jkl" I want to apply prefix and suffix to each value in the string without using any loops. Say if Prefix is Pre_ and Suffix is _Suf then I need to get ... (1 Reply)
Discussion started by: tostay2003
1 Replies
Login or Register to Ask a Question