Look up 2 files and print the concatenated output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Look up 2 files and print the concatenated output
# 8  
Old 03-18-2013
Is It working?

Code:
U="(TZ=IST+24 date +%a)"

you missed a $ sign here.

It should be

Code:
U=$(TZ=IST+24 date +%a)"

# 9  
Old 03-19-2013
Not working

I tried to use the variable it is giving error like not a valid token , can some one help.

Actually the file1.txt has multiple lines , i tried to join lines based on the date and day post which i am trying to the awk to merge the 2 files.

The command is failing
# 10  
Old 03-19-2013
Hi Aravind,

Your requirement is keep changing. Pls post , sample input and the output you are expecting from it ( mention the condition too ) . Use code tags to place your data.
# 11  
Old 03-19-2013
Update

$ cat f1
Sun Mar 17 00:01:33 2013
submit ,Name="1234"
Hello 123
how are you
Sun Mar 17 00:01:33 2013
submit , Name="1344"
Hello 345
how are you
Sun Mar 17 00:01:33 2013
submit , Name="1124"
Hello 456
how are you

Code:
$ nawk '/^Sun/ && p{print p;p=""}{p=p $0}END{if(p) print p}' f1 > f3.txt

Code:
nawk '/^`TZ=IST+24 Date + %a`/ && p{print p;p=""}{p=p $0}END{if(p) print p}' f1 > f3.txt

I executed the above script to join all the lines based on the Day . I am not able to give input as `TZ=IST+24 Date + %a` in this and if i give all the lines get concatenated and the whole file becomes 1 line.

But if i manually give expression as /^Sun/ it is working perfectly , but the same is not working if i try with `TZ=IST+24 Date + %a` as input.

Any solution to crack it.

Last edited by aravindj80; 03-19-2013 at 04:15 AM.. Reason: for updating
# 12  
Old 03-19-2013
Try like this:
Code:
$ awk -vDT=$(date +%a) '
         NR==FNR        {TMP[$6]=$7 FS $8; next}
         $0~DT          {getline X
                         $0=$0 ", "X
                         gsub (/[^0-9]/, "", X)
                         print $0, TMP[X]}
        ' file1 file
Sun Mar 17 00:01:33 2013, submit ,Name="1234" execute SUCCEEDED
Sun Mar 17 00:01:33 2013, submit ,Name="1344" execute FAILED
Sun Mar 17 00:01:33 2013, submit ,Name="1124" execute SUCCEEDED

# 13  
Old 03-19-2013
Help Required

Code:
nawk '/^Sun/ && p{print p;p=""}{p=p $0}END{if(p) print p}' f1 > f3

The above helps me to concatenate all the lines that are in between from the Sun to Next Sun.

Please tell me how i can replace /^Sun/ in the above script , that will be helpful.
# 14  
Old 03-19-2013
Code:
$ U="$(TZ=IST+24 date +%a)"

$ awk '/^'$U'/  && p{print p;p=""}{p=p $0}END{if(p) print p}' f1 > f3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare two files and print output

Hi All, i am trying to compare two files in Centos 6. F1: /tmp/d21 NAME="xvda" TYPE="disk" SIZE="40G" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="" NAME="xvda1" TYPE="part" SIZE="500M" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="/boot" NAME="xvda2" TYPE="part"... (2 Replies)
Discussion started by: balu1234
2 Replies

2. Shell Programming and Scripting

Awk: Print Error While Redirecting output in multiple Files

Hi, I have a following code in which I am unable to redirect to multiple files. Can anybody please help with some corrections awk -F, '{ if ( substr($1,26,2)=="02" && substr($1,184,14)=="MTSCC_VALFIRST") { array1++ array2++ array3++ } else if (substr($1,26,2)=="03" &&... (4 Replies)
Discussion started by: siramitsharma
4 Replies

3. Shell Programming and Scripting

Match two columns from two files and print output

Hello, I have two files which are of the following format File 1 which has two columns Protein_ID Substitution NP_997239 T53R NP_060668 V267M NP_058515 P856A NP_001206 T55M NP_006601 D371Y ... (2 Replies)
Discussion started by: nans
2 Replies

4. Shell Programming and Scripting

Comparing 2 xml files and print the differences only in output

Hi....I'm having 2 xml files, one is having some special characters and another is a clean xml file does not have any special characters. Now I need one audit kind of file which will show me only from which line the special characters have been removed and the special characters. Can you please... (1 Reply)
Discussion started by: Krishanu Saha
1 Replies

5. Shell Programming and Scripting

Print only lines where fields concatenated match strings

Hello everyone, Maybe somebody could help me with an awk script. I have this input (field separator is comma ","): 547894982,M|N|J,U|Q|P,98,101,0,1,1 234900027,M|N|J,U|Q|P,98,101,0,1,1 234900023,M|N|J,U|Q|P,98,54,3,1,1 234900028,M|H|J,S|Q|P,98,101,0,1,1 234900030,M|N|J,U|F|P,98,101,0,1,1... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

6. Shell Programming and Scripting

match two key columns in two files and print output (awk)

I have two files... file1 and file2. Where columns 1 and 2 of file1 match columns 1 and 2 of file2 I want to create a new file that is all file1 + columns 3 and 4 of file2 :b: Many thanks if you know how to do this.... :b: file1 31-101 106 0 92 31-101 106 29 ... (2 Replies)
Discussion started by: pelhabuan
2 Replies

7. UNIX for Dummies Questions & Answers

Getting non unique lines from concatenated files

Hi All, Is there a way to get NON unique lines from 2 or more concatenated files? Basically I have several files which are very similar with the exception of few lines and I want to find out which lines are different in each file. Very simple example is file1 contains: 1 2 3 4 5file2... (122 Replies)
Discussion started by: pawannoel
122 Replies

8. Shell Programming and Scripting

compare two files and search keyword and print output

You have two files to compare by searching keyword from one file into another file File A 23 >pp_ANSWER 24 >aa hello 25 >jau head wear 66 >jss oops 872 >aqq olps ploww oww sss 722 >GG_KILLER ..... large files File B Beta done KILLER John Mayor calix meyers ... (5 Replies)
Discussion started by: cdfd123
5 Replies

9. Shell Programming and Scripting

compare columns from seven files and print the output

Hi guys, I need some help to come out with a solution . I have seven such files but I am showing only three for convenience. filea a5 20 a8 16 fileb a3 42 a7 14 filec a5 23 a3 07 The output file shoud contain the data in table form showing first field of... (7 Replies)
Discussion started by: smriti_shridhar
7 Replies

10. Shell Programming and Scripting

awk to compare lines of two files and print output on screen

hey guys, I have two files both with two columns, I have already created an awk code to ignore certain lines (e.g lines that start with 963) as they wou ld begin with a certain string, however, the rest I have added together and calculated the average. At the moment the code also displays... (3 Replies)
Discussion started by: chlfc
3 Replies
Login or Register to Ask a Question