Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines
# 1  
Old 04-05-2014
Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines

I have a bunch of file numbers in the file 'test':

I'm trying the above command to change all the instances of "H" to "Na+" in the file testsds.pdb at the line numbers indicated in the file 'test'. I've tried the following and various similar alternatives but nothing is working:

Code:
cat test | while read line; do line=$line"s"; sed -i "$line/H  /Na+/" testsds.pdb >> well ; done

Any help would be greatly appreciated.
# 2  
Old 04-05-2014
Give us an example of the current data and expected changes...we shall try
This User Gave Thanks to SriniShoo For This Post:
# 3  
Old 04-05-2014
Try:
Code:
awk 'NR==FNR{a[$0]=1;next}a[FNR]==1{gsub ("H","Na+")}1' test testsds.pdb

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 04-05-2014
Code:
awk 'NR==FNR{a[$0]=1;next}a[FNR]==1{gsub ("H","Na+")}1' test testsds.pdb

^ works flawlessly, thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file lines and pass line values as arguments.

Dears, Need help to implement below requirement A file (detail.txt)contain : 1st column: Stream 2nd column: PathAddress 3rd column: Counterlimit 4th column: TransactionDateColumn 5th column: DateType 6th column: SleepValue 7th column: Status Need to write a... (1 Reply)
Discussion started by: sadique.manzar
1 Replies

2. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

3. Shell Programming and Scripting

Change numbers in flat file

Hi, I have some datatexts with values and I want to replace only the values of the first file with the result of array loaded in one variable. Also I want the operation difference with the original value replaced and only replace the new value not the character format of the file. Some Idea?... (24 Replies)
Discussion started by: faka
24 Replies

4. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

5. Shell Programming and Scripting

Change numbers in a file, incrementing them

Hello, Here's a file of mine: key1:431 key2:159 key3:998 I need to change these keys to something bigger - and I actually need to shift them all by a range of 3. The output would be: key1:434 key2:162 key3:1001 I can't find the propper sed/awk line that would alter all my... (4 Replies)
Discussion started by: fzd
4 Replies

6. UNIX for Dummies Questions & Answers

Editing strings within lines of file

Dear All, I have a file which contains a column with age, which is represented in two following patterns 1. "007/A" or ''007/a" or ''7 /a" ..... In this case A or a means year and I would like to extract only the numeric values eg 7 in the above case if this pattern exits in a line of file.... (5 Replies)
Discussion started by: pawannoel
5 Replies

7. UNIX for Dummies Questions & Answers

Finding numbers in lines with strings and number and doing some manipulation

Hi, I want to write a script that does something like this: I have a file, in which in every line, there is a string of words, and followed by some space, a number. Now, I want to identify the line, which has the largest startFace number (say m=8118), take that number and add it to the... (2 Replies)
Discussion started by: super_commando
2 Replies

8. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

9. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

10. Shell Programming and Scripting

Adding strings to lines in a file

Hi all, I have a positional text file that comes from some source application. Before it is processed by destination application I have to add some header (suffix) to every record(line) in the file. e.g. Actual File ............... AccountDetails AcNO Name Amount 1234 John 26578 5678... (3 Replies)
Discussion started by: sharath160
3 Replies
Login or Register to Ask a Question