Awk: first line not processed correctly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk: first line not processed correctly
# 1  
Old 08-07-2008
Awk: first line not processed correctly

Hey,

I've made a little awk-script which reorders lines.
Works okay, only problem is that is doesn't process the first line correctly.
If I switch lines in the Input file it doesn't proces this first line either.

Somebody please help!

Here's is the code and the input file!

thanx


Code:
awk 'FS=","{print $1","$2","$3","$4","$5","$6","$7","$8","$9";xf="$11";yf="$
12";,"$10}' Input > Output

Code:
Input
1,2,0,0,6,43,5,0,p1=Gmünd;p2=Austria;p8=Bad Großpertholz;fc=4,,1473937,4855256,1
2,3,0,0,6,43,5,0,p1=Gmünd;p2=Austria;p8=Bad Großpertholz;fc=4,Güterweg Gugu,1473760,4855398,2
2,4,0,0,6,43,5,0,p1=Gmünd;p2=Austria;p8=Bad Großpertholz;fc=4,,1473760,4855398,2

Code:
Output
1,2,0,0,6,43,5,0,p1=Gmünd;p2=Austria;p8=Bad,Großpertholz;fc=4,,1473937,4855256,1,,,,,,,;xf=;yf=;,
2,3,0,0,6,43,5,0,p1=Gmünd;p2=Austria;p8=Bad Großpertholz;fc=4;xf=1473760;yf=4855398;,Güterweg Gugu
2,4,0,0,6,43,5,0,p1=Gmünd;p2=Austria;p8=Bad Großpertholz;fc=4;xf=1473760;yf=4855398;,

# 2  
Old 08-07-2008
Try this (use nawk on Solaris, won't work with /usr/[/xpg4/]bin/awk):

Code:
awk -F, '{
  $(NF-4) = sprintf("%s;xf=%s;yf=%s;,%s",
  $(NF-4), $(NF-2), $(NF-1), $(NF-3))
  NF = NF-4 
  }1' OFS=, filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why does this awk script not work correctly?

I have a large database with English on the left hand side and Indic words on the left hand. It so happens that since the Indic words have been entered by hand, there are duplicates in the entries. The structure is as under: English headword=Indic gloss,Indic gloss A small sample will... (6 Replies)
Discussion started by: gimley
6 Replies

2. Shell Programming and Scripting

Check the file processed Completion

Hi, I have a wierd requirement where i need to check for a file transfered to my Server and once it is completed i need to start processing my jobs. My server is AIX 6.0 and i want to know is there some way in unix i can keep on checking the file and once it is completed successfully i can... (5 Replies)
Discussion started by: prasson_ibm
5 Replies

3. Shell Programming and Scripting

awk not working correctly

Hi I am attempting to right a script which will read a table and extract specfic information. LASTFAILEDJOB=/usr/openv/netbackup/scripts/GB-LDN/Junaid/temp_files/lastfailedjob cat /usr/openv/netbackup/scripts/GB-LDN/Junaid/temp_files/lastfailedjob 237308646 If i run the following... (5 Replies)
Discussion started by: Junes
5 Replies

4. Shell Programming and Scripting

CRON shell script only runs correctly on command line

Hi, I'm new to these forums, and I'm hoping that someone can solve this problem... To make things short: I have DD-wrt set up on a router. I'm trying to run a script in CRON that fetches the daily password from my database using SSH. CRON is set like so(in web interface): * * * *... (4 Replies)
Discussion started by: louieaw
4 Replies

5. UNIX for Dummies Questions & Answers

regex to split a line correctly

Hello, I'm working on a little project to extract weather data from website. At this point, I've stored each weather information on one line in a UNIX standard file. Each line has the structure: dd-mm-yy:City:dd-mm-yy:kind Of Data:value Of Data the first dd-mm-yy (it's the french format... (6 Replies)
Discussion started by: tevious
6 Replies

6. Shell Programming and Scripting

remember processed files

Hello dear community! I have the following task to accomplish: there is a directory with approximately 2 thousand files. I have to write a script which would randomly extract 200 files on the first run. On the second run it should extract again 200 files but that files mustn't intersect with... (5 Replies)
Discussion started by: sidorenko
5 Replies

7. Shell Programming and Scripting

Deleting processed lines

I have a log file that I am processing. This contains messages from and to a server (requests and responses). The responses to requests may not be in order i.e. we can have a response to a request after several requests are sent, and in some error cases there may not be any response message. ... (2 Replies)
Discussion started by: BootComp
2 Replies

8. Shell Programming and Scripting

awk script to remove spaces - examples don't show up correctly

I have the following data from a manual database dump. I need to format the columns so that I can import them into an excel spread sheet. So far I have been able to get past the hurdles with vi and grep. Now I have one last issue that I can't get past. Here is an example of the data. Here is... (18 Replies)
Discussion started by: Chris_Rivera
18 Replies

9. Shell Programming and Scripting

Grep/awk not getting the message correctly

I have a script which will take two file as the inputs and take the Value in file1 and search in file2 and give the output in Outputfile. #!/bin/sh #. ${HOME}/crossworlds/bin/CWSharedEnv.sh FILE1=$1 FILE2=$2 for Var in $(cat $FILE1);do echo $Var grep -i "$Var" $FILE2 done > Outputfile I... (2 Replies)
Discussion started by: SwapnaNaidu
2 Replies

10. Shell Programming and Scripting

Unable to display correctly the contents of a file without a line feed

I am using AIX and ksh. I need to display the contents of a file that has a pid (process id). Because the file is open, it doesn't have the line feed or new line, so for some reason if I do this: `cat $pid` , where $pid is the name of the fully qualified file, it displays test3.sh: 426110:... (1 Reply)
Discussion started by: Gato
1 Replies
Login or Register to Ask a Question