Read file data and send to different file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read file data and send to different file
# 1  
Old 11-19-2014
Read file data and send to different file

junk.txt has a single numerical value in it, let's say 50421.44.

over.namelist has lots of expressions in it, but somewhere random it says value = x.x

I need to go into junk.txt, pull out the number, and amend over.namelist to say value = 50421.44.

SmilieSmilie

I'm trying to use sed, but can't make it work. Something similar to:

Code:
sed -I 's/'x.x'/gawk '{print $1}' junk.txt/g' over.namelist

Any help?
# 2  
Old 11-19-2014
A better example of your input and desired output would be helpful...
# 3  
Old 11-19-2014
sed is not shell, gawk is not shell, and sed is not gawk. Mixing the three together inside each other is not going to work.

Code:
awk '/value/ { sub(/x[.]x/, VAL); } 1' VAL="12345.67" inputfile > outputfile

# 4  
Old 11-19-2014
I'm truly surprised, but following seems to work Smilie
Code:
sed -i 's/'x.x'/'"$(awk '{print $1}' junk.txt)"'/g' over.namelist

Note I used awk, actually mawk, because gawk is not installed on the machine I performed the test.
# 5  
Old 11-19-2014
junior-helper be careful of x.x as it would match in strings like "box xmas gifts". That is why Corona688 used x[.]x in his RE.

I'd also be tempted to remove some unnecessary quotes like this:

Code:
sed -i "s/x[.]x/$(awk '{print $1}' junk.txt)/g" over.namelist

This User Gave Thanks to Chubler_XL For This Post:
# 6  
Old 11-20-2014
How about doing it all in sed? Try
Code:
sed -r '1{h;d}; /value/{G;s/x\.x(.*)\n([0-9.]*)/\2\1/}' file1 file2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In PErl script: need to read the data one file and generate multiple files based on the data

We have the data looks like below in a log file. I want to generat files based on the string between two hash(#) symbol like below Source: #ext1#test1.tale2 drop #ext1#test11.tale21 drop #ext1#test123.tale21 drop #ext2#test1.tale21 drop #ext2#test12.tale21 drop #ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies

2. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

3. Shell Programming and Scripting

Read a file, add some text and send an email

Hi, If I am asking this question, you must have already figured out , that I am new to Unix, so here it goes I was trying to read a file, add some user defined content to it and send out an email , I did find out a way to achieve this, but looking at the code, it looks a bit crude to me, can... (3 Replies)
Discussion started by: karthikbhuvana
3 Replies

4. Shell Programming and Scripting

Read file, send to dig, no output

From the command line I am running the following command: for i in $(awk '{print ($1)}' src-dst|uniq); do dig -x "$i" +short; done src-dst has a list of IP addresses. When this script is running and I do a ps -ef | grep dig, I see the proper dig command with IP addresses being run, but the... (2 Replies)
Discussion started by: phish
2 Replies

5. Shell Programming and Scripting

Read file and send email

I have a file like this. I need to ues this file to send emails to the appropriate ID/group. For instance in the first line - Subject should be --> "A1.csv - ABC" - Body should be --> File A1.csv has changed. - Email should be sent to A1@xyz.com,A3@xyz.com Lookup.csv: ... (1 Reply)
Discussion started by: vskr72
1 Replies

6. Shell Programming and Scripting

Want to read data from a file name.txt and search it in another file and then matching...

Hi Frnds... I have an input file name.txt and another file named as source.. name.txt is having only one column and source is having around 25 columns...i need to read from name.txt line by line and search it in source file and then save the result in results file.. I have a rough idea about the... (15 Replies)
Discussion started by: ektubbe
15 Replies

7. Shell Programming and Scripting

Read the apecific data from one file and write into another file

Hi, I would like to read the specific data from file and write the data in the new file. My data input is something like this.. <EXROP:R=TJ0311T; ROUTE DATA R ROUTE PARAMETERS TJ0311T DETY=UPDR TTRANS=1 FNC=3 MA=628160955000 R=TJ0311D ... (3 Replies)
Discussion started by: bha148
3 Replies

8. Shell Programming and Scripting

Read the lines within file and send each line to different new file

I need help.....I have number of data files and I need to read the contains of each file which is three lines by awk commands or script, and send each line within the data file to different new file . That means I will have three files as a result, the first file will contains the first lines for... (4 Replies)
Discussion started by: aldreho
4 Replies

9. Shell Programming and Scripting

Read a file with in UNIX and send multiple mails

Hi-I want to create a shell script which should read a file line by line (file having email address and transaction id of each user)and send email on email ids with the transaction id of the user respectively. Please help - I think a while loop should help but I am very new too UNIX Shell... (1 Reply)
Discussion started by: DeepSalwan
1 Replies

10. Shell Programming and Scripting

Post Shell programming: Question about source a file and read data from the file

This is shell programming assignment. It needs to create a file called .std_dbrc contains STD_DBROOT=${HOME}/class/2031/Assgn3/STD_DB (which includes all my simple database files) and I am gonna use this .std_dbrc in my script file (read the data from the database files) like this: .... (3 Replies)
Discussion started by: ccwq
3 Replies
Login or Register to Ask a Question