Sponsored Content
Special Forums Windows & DOS: Issues & Discussions Extracting variables between commas : GAWK or SED Post 302496444 by jujulips on Monday 14th of February 2011 05:48:25 AM
Old 02-14-2011
I wrote this Batch File :
Code:
gawk 'NR==1{split($0,a,"/");next}
{print "IN\tTAUX" ++c "\t" a[3] a[2] a[1] "D\t"  $1 "\t" $1}
' RS=";" C:\file.txt
pause

Dos returns me this Error message :
Code:
C:\Documents and Settings\julien.lacombe\Desktop>gawk 'NR==1{split($0,a,"/");nex
t}
gawk: cmd. line:1: 'NR==1{split($0,a,/);next}
gawk: cmd. line:1: ^ invalid char ''' in expression

C:\Documents and Settings\julien.lacombe\Desktop>{print "IN\tTAUX" ++c "\t" a[3]
 a[2] a[1] "D\t"  $1 "\t" $1}
'{print' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\julien.lacombe\Desktop>' RS=";" C:\file.txt
''' is not recognized as an internal or external command,
operable program or batch file.

C:\Documents and Settings\julien.lacombe\Desktop>pause
Press any key to continue . . .

Thanks for your time, I'm currently learning Batch et Gawk scripting !

---------- Post updated at 05:48 AM ---------- Previous update was at 05:43 AM ----------

I changed my Batch file into :

Code:
gawk "NR==1{split($0,a,"/");next}{print "IN\tTAUX" ++c "\t" a[3] a[2] a[1] "D\t"  $1 "\t" $1}" RS=";" C:\file.txt 
pause


And dos returns me this Error :

Code:
C:\Documents and Settings\julien.lacombe\Desktop>gawk "NR==1{split($0,a,"/");nex
t}{print "IN\tTAUX" ++c "\t" a[3] a[2] a[1] "D\t"  $1 "\t" $1}" RS=";" C:\file.t
xt
gawk: cmd. line:1: NR==1{split($0,a,/);next}{print IN\tTAUX ++c \t a[3] a[2] a[1
] D\t  $1 \t $1}
gawk: cmd. line:1:                   ^ unterminated regexp
gawk: cmd. line:2: NR==1{split($0,a,/);next}{print IN\tTAUX ++c \t a[3] a[2] a[1
] D\t  $1 \t $1}
gawk: cmd. line:2:
                ^ unexpected newline

C:\Documents and Settings\julien.lacombe\Desktop>pause
Press any key to continue . . .

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to use variables and gawk in a script?

Hi, I want to define variables in a shell script and make gawk use them to make some operations Mfn = $(grep " 1 " $fitxer | gawk '{print $2}') Xfn = $(grep " 1 " $fitxer | gawk '{print $3}') Yfn = $(grep " 1 " $fitxer | gawk '{print $4}') Zfn = $(grep " 1 " $fitxer | gawk... (9 Replies)
Discussion started by: pau
9 Replies

2. UNIX for Dummies Questions & Answers

Inserting commas and replacing backslashes with commas

Hi, Newbie here. I have a file that consists of data that I want to convert to a csv file. For example: Jul 20 2008 1111 / visit home / BlackBerry8830/4.2.2 Profile/MIDP-2.0 Configuration/CLOC-1.1 VendorID/105 Jul 21 2008 22222 / add friend / BlackBerry8830/4.2.2 Profile/MIDP-2.0... (3 Replies)
Discussion started by: kangaroo
3 Replies

3. Shell Programming and Scripting

Extracting strings surrounded by parentheses and seperate by commas

Excuse the terrible title. I have a text file of 1..n lines, each one containing at least one string between parentheses. Within each string, there is one or more strings separated by commas. I need to extract each string, thus: input file: (THIS,THAT) (THE,OTHER) (THING) (OR,MAYBE)... (6 Replies)
Discussion started by: kpfeif
6 Replies

4. Shell Programming and Scripting

Editing Commas in a textfile using sed

Hi guys task removing the last commas of 5th and 6th columns. The bug in the script is causing effect because of whitespaces around commas. I tried to delete white spaces first and running the above script. but still some where getting the results wrong. I already have a script to do this... (12 Replies)
Discussion started by: repinementer
12 Replies

5. Shell Programming and Scripting

Select ip and date using sed or gawk

1.56.253.48 - - "GET " 1.6.253.48 - - "GET " 1.65.253.48 - - "GET " 1.65.253.48 - - "GET " 1.63.53.48 - - "GET " 1.65.253.48 - - "GET " 1.16.23.48 - - "GET " 1.64.25.48 - - "GET " need command which give the output 1.6.253.48 - 09/Nov/2009:07:02:24 1.65.253.48 -... (7 Replies)
Discussion started by: sagar_evc
7 Replies

6. Shell Programming and Scripting

Extracting variables from echo

Hello all. I can not remember the command to extract a variable from the date command. Basically what I need to do is to store the values of date in variable and rearrange them. I can not remember the command or the syntax to do so. so.. date Mon Mar 8 06:57:19 GMT 2010 $1 $2 ... (12 Replies)
Discussion started by: adelsin
12 Replies

7. Shell Programming and Scripting

Help with sed and replacing white spaces with commas

Dear all, I am in a bit of a quandary. I have 400 text files which I need to edit and output in a very specific way. Here is a sample text file copied from gedit ... The columns will come out a bit messed up but when I cat <file>, it gives a table with six columns (0-28, tot lob vol, vcsf,... (6 Replies)
Discussion started by: antonz
6 Replies

8. Shell Programming and Scripting

extracting substrings from variables

Hello Everyone, I am looking for a way to extract substrings to local variables. Here is the format of the string variable i am using : /var/x/www && /usr/x/share/doc && /etc/x/logs where the substrings i must extract are the "/var/x/www" and such. I was originally thinking of using... (15 Replies)
Discussion started by: jimmy75_13
15 Replies

9. Shell Programming and Scripting

HELP with AWK or SED. Need to replace the commas between double quotes in CSV file

Hello experts, I need to validate a csv file which contains data like this: Sample.csv "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 "ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0 I just need to check if all the records contain exactly the number of... (5 Replies)
Discussion started by: shell_boy23
5 Replies

10. Shell Programming and Scripting

Gawk and sed question

Can anyone tell me what this script does? sort file1.txt | awk -F, -f event.gawk Thank you. (2 Replies)
Discussion started by: dee campbell
2 Replies
TRACE-CMD-OPTIONS(1)													      TRACE-CMD-OPTIONS(1)

NAME
trace-cmd-options - list available options from trace-cmd plugins SYNOPSIS
trace-cmd options DESCRIPTION
The trace-cmd(1) options command will examine all the trace-cmd plugins that are used by trace-cmd report(1) and list them. SEE ALSO
trace-cmd(1), trace-cmd-record(1), trace-cmd-start(1), trace-cmd-stop(1), trace-cmd-extract(1), trace-cmd-reset(1), trace-cmd-split(1), trace-cmd-list(1), trace-cmd-listen(1) AUTHOR
Written by Steven Rostedt, <rostedt@goodmis.org[1]> RESOURCES
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git COPYING
Copyright (C) 2011 Red Hat, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL). NOTES
1. rostedt@goodmis.org mailto:rostedt@goodmis.org 06/11/2014 TRACE-CMD-OPTIONS(1)
All times are GMT -4. The time now is 10:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy