nawk script to manipulate txt file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting nawk script to manipulate txt file
# 8  
Old 10-03-2012
Good choice chubler.
# 9  
Old 10-03-2012
Quote:
Originally Posted by Chubler_XL
How about:

Code:
join -a 1 -t, -o 1.2 2.2 2.3 txt1 txt2

result:

Code:
,,
,,LOGOFF
,,LOGOFF
,,LOGOFF
,,LOGOFF

---------- Post updated at 11:28 AM ---------- Previous update was at 11:23 AM ----------

Quote:
Originally Posted by jim mcnamara
try:
Code:
# solaris use nawk not awk
awk -F'[ ,]'   ' FILENAME=="txt1" {arr[$1]++}
                FILENAME=="txt2" {arr[$1]++; print $0}
                END{ for (i in arr) {if(arr[i]==1){printf("%s%s\n", i,", ,LOGOFF" )  } } } ' txt1 txt2  > newfile

start with that to see if it is what you want.
Code:
awk: syntax error near line 3
awk: illegal statement near line 3
awk: syntax error near line 3
awk: illegal statement near line 3

# 10  
Old 10-03-2012
What Os and awk are you using? I tried this on some dummy files, got no errors (cygwin & gawk) Are you sure you copied and pasted the code correctly. Look at the code you have and be sure you do not have something odd on line 3.
# 11  
Old 10-03-2012
Quote:
Originally Posted by jim mcnamara
What Os and awk are you using?
SunOS ops2gw1 5.10 Generic_144488-07 sun4u sparc SUNW,Netra-T12

/usr/xpg4/bin/awk

---------- Post updated at 11:47 AM ---------- Previous update was at 11:34 AM ----------

Quote:
Originally Posted by Chubler_XL
How about:

Code:
join -a 1 -t, -o 1.2 2.2 2.3 txt1 txt2

can i do this:

Code:
join -a 1 -t, -o 1.2 2.2 2.3 txt1 txt2 > new file

# 12  
Old 10-03-2012
Oops typo in my post try:

Code:
join -a 1 -t, -o 1.1 2.2 2.3 txt1 txt2

Might also have to throw a sed in if you want LOGOFF on missing lines:

Code:
join -a 1 -t, -o 1.1 2.2 2.3 txt1 txt2 | sed 's/,,$/,,LOGOFF/'

This User Gave Thanks to Chubler_XL For This Post:
# 13  
Old 10-03-2012
Quote:
Originally Posted by Chubler_XL
Oops typo in my post try:

Code:
join -a 1 -t, -o 1.1 2.2 2.3 txt1 txt2

Might also have to throw a sed in if you want LOGOFF on missing lines:

Code:
join -a 1 -t, -o 1.1 2.2 2.3 txt1 txt2 | sed 's/,,$/,,LOGOFF/'

Almost there
Code:
TQC101,,LOGOFF
TQC102,,LOGOFF
TQC102,,LOGOFF
TQC103,,LOGOFF
TQC103,,LOGOFF
TQC104,2012-10-03 07:42:57,LOGON
TQC104,2012-10-03 07:42:57,LOGON

I got duplicate rows
# 14  
Old 10-03-2012
Umm, no duplicates here (Tested on AIX, Redhat Linux and cygwin).
Wonder if they are comming from sed or join.
Can you try without the sed command?

Hate to suggest this, but as a workaround you could throw | uniq on the end of the pipeline.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Call a Perl script within a bash script and store the ouput in a .txt file

I'm attempting to write a bash script that will create a network between virtual machines. It accepts three arguments: an RSpec that describes the network topology, and two list of machines (servers and clients). I have a (working) Perl script that I want to call. This Perl script takes an RSpec... (6 Replies)
Discussion started by: mecaka
6 Replies

3. 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

4. Shell Programming and Scripting

How to print and append output of nawk script in commandline and as well into a file?

Hi All, I am working on nawk script, has the small function which prints the output on the screen.Am trying to print/append the same output in a file. Basically nawk script should print the output on the console/screen and as well it should write/append the same result to a file. script :... (3 Replies)
Discussion started by: Optimus81
3 Replies

5. 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

6. Shell Programming and Scripting

Nawk script to compare records of a file based on a particular column.

Hi Gurus, I am struggling with nawk command where i am processing a file based on columns. Here is the sample data file. UM113570248|24-AUG-11|4|man1|RR211 Alert: Master Process failure |24-AUG-11 UM113570624|24-AUG-11|4|man1| Alert: Pattern 'E_DCLeDAOException' found |24-AUG-11... (7 Replies)
Discussion started by: usha rao
7 Replies

7. Shell Programming and Scripting

Shell script to manipulate a file

Hello, I have a file with following contents : WSL SRVGRP=LISTENER SRVID=2 CLOPT="-A -t -- -n 0x0002aa050a03cc65 " RQPERM=0660 REPLYQ=Y RPPERM=0660 MIN=1 MAX=1 CONV=N I need to print only the value in Hex i.e.... (2 Replies)
Discussion started by: deo_kaustubh
2 Replies

8. Shell Programming and Scripting

sed script to manipulate the /etc/passwd file

Hi. Can anybody help me with a script to extract usernames, shell and home_directory from the /etc/passwd file. I am stuck (2 Replies)
Discussion started by: Pauline mugisha
2 Replies

9. UNIX for Dummies Questions & Answers

Binary txt file received when i use uuencode to send txt file as attachment

Hi, I have already read a lot of posts on sending attachments in unix...but none of them were of help for my problem...so here goes.. i wanna attach a text file and send to a mail id..used the following code : uuencode "$File1" "$File1" ;|mail -s "$Mail_sub" abc@abc.com it works... (2 Replies)
Discussion started by: ash22
2 Replies

10. Shell Programming and Scripting

unix script to takes the old data from a TXT file and compress them into new file

Hi, I am looking for the unix script which can takes the 2 month old data from a TXT file (there is one txt file in whiche messages are appended on daily basis) and compress them into new file.Please halp me out. (2 Replies)
Discussion started by: vpandey
2 Replies
Login or Register to Ask a Question