AWK error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK error
# 1  
Old 09-12-2011
AWK error

Any ideas why I am having this issue?
Code:
$ cat test4.csv
8-29-2011,022202,24,333
8-29-2011,033303,24,222
8-29-2011,044404,24,111
8-29-2011,055550,24,222
8-29-2011,066606,24,333
8-29-2011,077707,24,111
8-29-2011,088808,24,222
8-29-2011,099909,24,444 434
8-29-2011,030303,24,222
8-29-2011,040404,24,111


Code:
$ awk 'BEGIN{FS=OFS=","} { print $2,$4,$3,$1}' test4.csv
,24,8-29-2011
,24,8-29-2011
,24,8-29-2011
,24,8-29-2011
,24,8-29-2011
,24,8-29-2011
,24,8-29-2011
,24,8-29-20114
,24,8-29-2011
040404,111,24,8-29-2011


Last edited by Franklin52; 09-13-2011 at 03:15 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 09-12-2011
Something wrong with your file or awk. Give the output of the next commands:
1. xxd test4.cvs (or od -xc)
2. uname -a (or just say your OS).
# 3  
Old 09-13-2011
Below command looks okay and i tried it is working fine.
Quote:
awk 'BEGIN{FS=OFS=","} { print $2,$4,$3,$1}' test4.csv
# 4  
Old 09-13-2011
Quote:
Originally Posted by ffdstanley
Any ideas why I am having this issue?
You have a carriage return, \r, at the end of every line except the last one.

Regards,
Alister

Last edited by alister; 09-13-2011 at 02:57 AM.. Reason: Added quoted text
This User Gave Thanks to alister For This Post:
# 5  
Old 09-13-2011
output

Code:
doug@doug-desktop:~/Desktop$ xxd test4.csv
0000000: 382d 3239 2d32 3031 312c 3032 3232 3032  8-29-2011,022202
0000010: 2c32 342c 3333 330d 0a38 2d32 392d 3230  ,24,333..8-29-20
0000020: 3131 2c30 3333 3330 332c 3234 2c32 3232  11,033303,24,222
0000030: 0d0a 382d 3239 2d32 3031 312c 3034 3434  ..8-29-2011,0444
0000040: 3034 2c32 342c 3131 310d 0a38 2d32 392d  04,24,111..8-29-
0000050: 3230 3131 2c30 3535 3535 302c 3234 2c32  2011,055550,24,2
0000060: 3232 0d0a 382d 3239 2d32 3031 312c 3036  22..8-29-2011,06
0000070: 3636 3036 2c32 342c 3333 330d 0a38 2d32  6606,24,333..8-2
0000080: 392d 3230 3131 2c30 3737 3730 372c 3234  9-2011,077707,24
0000090: 2c31 3131 0d0a 382d 3239 2d32 3031 312c  ,111..8-29-2011,
00000a0: 3038 3838 3038 2c32 342c 3232 320d 0a38  088808,24,222..8
00000b0: 2d32 392d 3230 3131 2c30 3939 3930 392c  -29-2011,099909,
00000c0: 3234 2c34 3434 2034 3334 0d0a 382d 3239  24,444 434..8-29
00000d0: 2d32 3031 312c 3033 3033 3033 2c32 342c  -2011,030303,24,
00000e0: 3232 320d 0a38 2d32 392d 3230 3131 2c30  222..8-29-2011,0
00000f0: 3430 3430 342c 3234 2c31 3131 0a         40404,24,111.
doug@doug-desktop:~/Desktop$ uname -a
Linux doug-desktop 2.6.27-11-generic #1 SMP Thu Jan 29 19:24:39 UTC 2009 i686 GNU/Linux

Moderator's Comments:
Mod Comment Please use code tags for code and data samples!

Last edited by radoulov; 09-13-2011 at 08:01 AM..
# 6  
Old 09-13-2011
Yes. Your file is in DOS format and you have to convert it to unix. See: How do I convert between Unix and Windows text files? - Knowledge Base
This User Gave Thanks to yazu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Error in awk...

Hi friends... (Apoloigies for any typos.) (Don, thanks for your input.) Consider these two code snippets:- awkerror1.awk #!/usr/bin/awk -f BEGIN \ { SAWTOOTHPLUS64 = " !#$&\'\)*,-/0235689:<>?ABDEGHJKMNPQSTVWYZ\\^_abdeghjkmnpqstvwyz|}~" for(LOOP = 1; LOOP <= 13; ++LOOP) {... (3 Replies)
Discussion started by: wisecracker
3 Replies

2. Shell Programming and Scripting

awk output yields error: awk:can't open job_name (Autosys)

Good evening, Im newbie at unix specially with awk From an scheduler program called Autosys i want to extract some data reading an inputfile that comprises jobs names, then formating the output to columns for example 1. This is the inputfile: $ more MapaRep.txt ds_extra_nikira_usuarios... (18 Replies)
Discussion started by: alexcol
18 Replies

3. Shell Programming and Scripting

Error with awk

i have been trying to run the following bash script, but get error: awk: cmd. line:1: - awk: cmd. line:1: ^ unexpected newline or end of string I have been trying to figure out what the problem is but to no avail. I need to run the script urgently for a project, so any help will be highly... (5 Replies)
Discussion started by: anti_antaeus
5 Replies

4. Shell Programming and Scripting

awk Error

Hi I am trying to create a file with count of lines and string from shell variable, i am getting the error incorrect syntax. Below is the code : wc -l $filename | awk '{ print $1"|"$2"|"${SOURCETYPE} }'>>$AUDITFILENAME Could someone help me on this? (7 Replies)
Discussion started by: cnrj
7 Replies

5. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

6. Shell Programming and Scripting

AWK error

This is my disk space on solaris box and i wrote a simple script which identifies mount points which crosses 90% or above. But the AWK part is throwing some error and im unable to debug.. mzaheer @ UAT 144 % => df -k Filesystem kbytes used avail capacity Mounted on... (5 Replies)
Discussion started by: user__user3110
5 Replies

7. Shell Programming and Scripting

Awk error -- awk: 0602-562 Field $() is not correct.

typeset -i i=1 while read -r filename; do Splitfile=`$Targetfile_$i.txt` awk 'substr($0,1,5) == substr($filename,1,5) && substr($0,526,2) == substr($filename,6,2) && substr($0,750,12) == substr($filename,8,12)' $SourceFilename >> $Splitfile i=i+1 done < /tmp/list.out I am using this logic... (1 Reply)
Discussion started by: pukars4u
1 Replies

8. UNIX for Dummies Questions & Answers

awk error

Hi all, i have the files in the below sequence: fancy_LANG_STD_AU_2008-03-05.dat fancy_LANG_STD_HK_2008-03-06.dat fancy_LANG_STD_NZ_2008-03-05.dat fancy_STD_AU_2008-03-05.dat fancy_STD_HK_2008-03-06.dat fancy_STD_NZ_2008-03-05.dat i am trying to sort them like below: ... (3 Replies)
Discussion started by: gyankr
3 Replies

9. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

10. Shell Programming and Scripting

Error in awk

var1=`echo "emp,dept,salgrade" | awk -F, '{print NF}'` count=1 while ; do i=`expr $count` tname=`echo "emp,dept,salgrade" | awk -F, '{ print $(echo $i) }'` count=$count+1; echo ${tname}; echo $count done I want to store in tname=emp, tname=dept,tname=salgrade I am getting... (2 Replies)
Discussion started by: dreams5617
2 Replies
Login or Register to Ask a Question