Bash incert line from 1.txt to 2.txt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash incert line from 1.txt to 2.txt
# 1  
Old 02-16-2017
Bash incert line from 1.txt to 2.txt

i would like to insert a line from 2.txt into 1.txt between " and "

or a way of adding to the end of each line " _01_ and have the numbers
correspond to the line #

1.txt=
Code:
foofoo "" _01_
foofoo "" _02_
foofoo "" _03_
foofoo "" _04_

2.txt=
Code:
xttps://111..............................................................................Yp
xttps://222..............................................................................Yp
xttps://333..............................................................................Yp
xttps://444..............................................................................Yp

output.txt
Code:
foofoo "xttps://111..............................................................................Yp" _01_
foofoo "xttps://222..............................................................................Yp" _02_
foofoo "xttps://333..............................................................................Yp" _03_
foofoo "xttps://444..............................................................................Yp" _04_

if you could point me in the right direction i'v been looking at sed and awk thank you in advance .

Last edited by vgersh99; 02-16-2017 at 07:59 PM.. Reason: code tags, please!
# 2  
Old 02-16-2017
Code:
awk -v qq='"' 'FNR==NR{a[FNR]=$0;next} {sub(qq qq, qq a[FNR] qq)}1' klein2.txt klein1.txt

# 3  
Old 02-16-2017
thank you vgersh99
that worked almost perfect except when awk comes across & in the html line it replaces & with ""
# 4  
Old 02-16-2017
Quote:
Originally Posted by klein
thank you vgersh99
that worked almost perfect except when awk comes across & in the html line it replaces & with ""
care to provide a sample record where the code breaks?

Sent from my Lenovo B8080-F using Tapatalk
# 5  
Old 02-16-2017
sorry about the xxx's but i'm not allowed to post html yet

before awk what the xttps should look like
Code:
xttps://www.xxxxxx.com/xxxxxx?v=m1PRD0kMgI8&list=PLCAAA4629624F20D8&xxxxxx=1


after awk what the xttps looks like
Code:
./xxxxx_xxxxx.pl "xttps://www.xxxxxx.com/xxxxxx?v=m1PRD0kMgI8""list=PLCAAA4629624F20D8""xxxxxx=1" _01_


i tryed using sed
Code:
sed 's/""/&/g' ouyput > overnight.sh

but it didn't work, but i can use find and replace in pluma , would like to automate it.
# 6  
Old 02-16-2017
Quote:
Originally Posted by klein
sorry about the xxx's but i'm not allowed to post html yet

before awk what the xttps should look like
Code:
xttps://www.xxxxxx.com/xxxxxx?v=m1PRD0kMgI8&list=PLCAAA4629624F20D8&xxxxxx=1

after awk what the xttps looks like
Code:
./xxxxx_xxxxx.pl "xttps://www.xxxxxx.com/xxxxxx?v=m1PRD0kMgI8""list=PLCAAA4629624F20D8""xxxxxx=1" _01_

i tryed using sed
Code:
sed 's/""/&/g' ouyput > overnight.sh

but it didn't work, but i can use find and replace in pluma , would like to automate it.
a different approach:
Code:
awk -F'"' 'FNR==NR{a[FNR]=$0;next} {$2=a[FNR]}1' OFS='"' klein2.txt klein1.txt

# 7  
Old 02-16-2017
thank you vgersh99
that worked perfect
This User Gave Thanks to klein For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

3. Shell Programming and Scripting

Desired output.txt for reading txt file using awk?

Dear all, I have a huge txt file (DATA.txt) with the following content . From this txt file, I want the following output using some shell script. Any help is greatly appreciated. Greetings, emily DATA.txt (snippet of the huge text file) 407202849... (2 Replies)
Discussion started by: emily
2 Replies

4. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

5. Shell Programming and Scripting

Delete file2.txt from file1.txt using scripting

Hi, I`m a total newbie, well my requirement is that i have 2 files I want to identify which countries i do not currently have in db.. how can i use the grep or another command to find this file .. i want to match all-countries.txt with countries-in-db.txt so the output is equal to... (11 Replies)
Discussion started by: beanbaby
11 Replies

6. Shell Programming and Scripting

awk append fileA.txt to growing file B.txt

This is appending a column. My question is fairly simple. I have a program generating data in a form like so: 1 20 2 22 3 23 4 12 5 43 For ever iteration I'm generating this data. I have the basic idea with cut -f 2 fileA.txt | paste -d >> FileB.txt ???? I want FileB.txt to grow, and... (4 Replies)
Discussion started by: theawknewbie
4 Replies

7. UNIX for Dummies Questions & Answers

find lines in file1.txt not found in file2.txt memory problem

I have a diff command that does what I want but when comparing large text/log files, it uses up all the memory I have (sometimes over 8gig of memory) diff file1.txt file2.txt | grep '^<'| awk '{$1="";print $0}' | sed 's/^ *//' Is there a better more efficient way to find the lines in one file... (5 Replies)
Discussion started by: raptor25
5 Replies

8. Shell Programming and Scripting

sed to read x.txt and grep from y.txt

How would I write a command(s) to read from a file (list) that looks like this: 29847374384 and grep from a second file (list) that looks like this: 29847374384, jkdfkjdf,3833,ddd:confused: (1 Reply)
Discussion started by: smellylizzard
1 Replies

9. Shell Programming and Scripting

command to list .txt and .TXT file

Hi expersts, in my directory i have *.txt and *.TXT and *.TXT.log, *.txt.log I want list only .txt and .TXT files in one command... how to ?? //purple (1 Reply)
Discussion started by: thepurple
1 Replies

10. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies
Login or Register to Ask a Question