sed with awk in loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed with awk in loop
# 1  
Old 08-13-2008
sed with awk in loop

Hi Guys,
I am using following code to do some task.
Can somebody please help me to use a for loop for this ?

___________________________________________________

sed s/DATA2/`awk '/ / {print $1}' formated1`/ EOD_Batch > EOD_Batch1
sed s/DATA3/`awk '/ / {print $2}' formated1`/ EOD_Batch1 > EOD_Batch
sed s/DATA4/`awk '/ / {print $3}' formated1`/ EOD_Batch > EOD_Batch1
sed s/DATA5/`awk '/ / {print $4}' formated1`/ EOD_Batch1 > EOD_Batch
sed s/DATA6/`awk '/ / {print $5}' formated1`/ EOD_Batch > EOD_Batch1
sed s/DATA7/`awk '/ / {print $6}' formated1`/ EOD_Batch1 > EOD_Batch
sed s/DATA8/`awk '/ / {print $7}' formated1`/ EOD_Batch > EOD_Batch1
sed s/DATA9/`awk '/ / {print $8}' formated1`/ EOD_Batch1 > EOD_Batch
sed s/DATA10/`awk '/ / {print $9}' formated1`/ EOD_Batch > EOD_Batch1
sed s/DATA11/`awk '/ / {print $10}' formated1`/ EOD_Batch1 > EOD_Batch
sed s/DATA12/`awk '/ / {print $11}' formated1`/ EOD_Batch > EOD_Batch1
sed s/DATA13/`awk '/ / {print $12}' formated1`/ EOD_Batch1 > EOD_Batch
sed s/DATA14/`awk '/ / {print $13}' formated1`/ EOD_Batch > EOD_Batch1
sed s/DATA15/`awk '/ / {print $14}' formated1`/ EOD_Batch1 > EOD_Batch
sed s/DATA16/`awk '/ / {print $15}' formated1`/ EOD_Batch > EOD_Batch1
______________________________________________________________
# 2  
Old 08-14-2008
Any Sample input and Sample output??
# 3  
Old 08-15-2008
Thanks for going through ..

What I am trying to do is ...

File 1) EOD_Batch
DATA2
DATA3
...
...
DATA16


Replace the records with values from file formated1

File 2) formated1
10 20 30 ..150


so that at the end EOD_Batch should be
10
20
30
...

..
150


--------------

In the file EOD_Batch , purposely I am not starting from DATA1 ..because if I replace DATA1 with some value ..it will also replace DATA11 as

DATA11= 'DATA1'1.

I could also create EOD_Batch1 , EOD_Batch2 , EOD_Batch3 ...after every replacement but then I need to delete 14 files ( EOD_Batch2 ..15 ) .
Off course ,if we are applying for loop that will be easier ...


I am looking for something like this

for i in 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
do
sed s/DATA($i)/`awk '/ / {print $($i-1)}' formated1`/ EOD_Batch > EOD_Batch($i)
done

Hope this will help....

Regards..
# 4  
Old 08-15-2008
For what i see as your output, are you trying to put the text from file formated1 to rows?
If so this should help :
awk 'gsub(/ /,"\n") {print}' a.txt
# 5  
Old 08-15-2008
Please provide a clearer example of what the input / output looks like Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk programming -Passing variable to awk for loop

Hi All, I am new to AWK programming. I have the following for loop in my awk program. cat printhtml.awk: BEGIN -------- <some code here> END{ ----------<some code here> for(N=0; N<H; N++) { for(M=5; M<D; M++) print "\t" D ""; } ----- } ... (2 Replies)
Discussion started by: ctrld
2 Replies

2. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

3. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

4. UNIX for Dummies Questions & Answers

Using sed in a for loop

Hi, I have a file called 1.txt, I want to create 2.txt through 100.txt using a for loop. In each instance of the loop, I want to change all "1"'s in the text file to "2"s and so on... I tried the code below to do this: for i in {2..100}; do sed 's/1/$i/g' 1.txt > $i.txt; done but it... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. UNIX for Dummies Questions & Answers

Using sed in a for loop

Hello I have a group of files a1.profile a2.profile a3.profile a4.profile b1.profile b2.profile b3.profile b4.profile These files all have the same first line with a value s1 atop the columns s1_context s1_ref s1_sample s1_% etc I am trying to use sed in a for loop to replace the s1 in the... (2 Replies)
Discussion started by: plumb_r
2 Replies

6. Shell Programming and Scripting

SED/AWK maybe PERL in a WHILE loop

Hi, I have a file containing numerous string values, for example: AMFU8849636 CCLU7120334 GESU5784065 TEMU3070096I have a second file with multiple records, such as the one below that I would like to manipulate based on the strings from the first file: CATOS2EDI DSTOW ABC ... (7 Replies)
Discussion started by: doza22
7 Replies

7. Shell Programming and Scripting

Comparison and editing of files using awk.(And also a possible bug in awk for loop?)

I have two files which I would like to compare and then manipulate in a way. File1: pictures.txt 1.1 1.3 dance.txt 1.2 1.4 treehouse.txt 1.3 1.5 File2: pictures.txt 1.5 ref2313 1.4 ref2345 1.3 ref5432 1.2 ref4244 dance.txt 1.6 ref2342 1.5 ref2352 1.4 ref0695 1.3 ref5738 1.2... (1 Reply)
Discussion started by: linuxkid
1 Replies

8. Shell Programming and Scripting

Using sed in for loop

I have a file MAT.txt which contains the following data: mat1.txt mat2.txt . . . . mat100.txt I want to remove the '.txt' from every line and have an output file with the following data: mat1 mat2 . . . . mat100 I know this can be done with sed easily for each line, but I do... (8 Replies)
Discussion started by: ursaan
8 Replies

9. Shell Programming and Scripting

For loop with sed

Hi there, I have 1 file with different 144 lines and 144 files that I want to change with a sed. What I want to do is to go trough the file with the 144 different lines take the line a replace a certain pattern with said in the first file of the folder where the 144 files are. Take the second... (3 Replies)
Discussion started by: sickboy
3 Replies

10. Shell Programming and Scripting

Use loop in sed or awk?

I know a little bit of sed and awk, but not too much. can loop be done in sed. Baiscally what I want is: file1: aaa 111 bbb 222 ccc 333 ddd 444 eee 555 fff 666 Note: the space in between is "tab" file2: bbb ddd eee I want delete any entries in file1... (4 Replies)
Discussion started by: redstone
4 Replies
Login or Register to Ask a Question