Problem creating file with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem creating file with awk
# 1  
Old 11-25-2010
Problem creating file with awk

Hello,

I don't understand why the script below doesn't act the way it should :

Code:
#!/bin/sh
awk 'BEGIN{printf("Entrez la date : "); getline date < "-"}
$0 ~ date {f=1;print;next}
/^[0-9]{2}\//{f=0}
f' Planning.csv > planning.txt

It doesn't create file planning.txt with only the result of the awk command but with the entire file in input... ???

Do you know why ?
# 2  
Old 11-25-2010
Post input file contents as well as string that you are entering when script asks you to do so.
# 3  
Old 11-25-2010
Hi,

Below the input file

Code:
01/12/2010;;;
Action_1;"XXXZZ24";Comment1;"Comment2"
Action_2;"XXXZZ25";Comment1;"Comment2"
Action_3;"XXXZZ26";Comment1;"Comment2"
Action_4;"XXXZZ27";Comment1;"Comment2"
Action_5;"XXXZZ28";Comment1;"Comment2"
Action_6;"XXXZZ29";Comment1;"Comment2"
Action_7;"XXXZZ30";Comment1;"Comment2"
02/12/2010;;;
Action_8;"XXXZZ31";Comment1;"Comment2"
Action_9;"XXXZZ32";Comment1;"Comment2"
Action_0;"XXXZZ33";Comment1;"Comment2"
Action_1;"XXXZZ24";Comment1;"Comment2"
Action_5;"XXXZZ35";Comment1;"Comment2"
Action_6;"XXXZZ36";Comment1;"Comment2"
Action_2;"XXXZZ25";Comment1;"Comment2"

When the scripts asks for a date and you enter 01/12/2010 it doesn't create the desired file containing only

Code:
01/12/2010;;;
Action_1;"XXXZZ24";Comment1;"Comment2"
Action_2;"XXXZZ25";Comment1;"Comment2"
Action_3;"XXXZZ26";Comment1;"Comment2"
Action_4;"XXXZZ27";Comment1;"Comment2"
Action_5;"XXXZZ28";Comment1;"Comment2"
Action_6;"XXXZZ29";Comment1;"Comment2"
Action_7;"XXXZZ30";Comment1;"Comment2"

Thanks
# 4  
Old 11-25-2010
Change this:
Code:
/^[0-9]{2}\//{f=0}

to
Code:
/^[0-9][0-9]\//{f=0}

Awk doesn't accept curly bracket syntax Smilie
# 5  
Old 11-25-2010
Thanks but it's not OK because I wanted awk to parse Planning.csv for a certain date and have the result in another file, that's why I added
Code:
f' Planning.csv > planning.txt

But the script hangs... Smilie
# 6  
Old 11-25-2010
Did you run it like this?
Code:
#!/bin/sh
awk 'BEGIN{printf("Entrez la date : "); getline date < "-"}
$0 ~ date {f=1;print;next}
/^[0-9][0-9]\//{f=0}
f' Planning.csv > planning.txt

# 7  
Old 11-25-2010
Yes this is the way I wrote the script
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating new users using a text file as imput (using only shell script and/or awk)

I need somebody who could help with an exercise. You have a text file called users.txt with this info inside: users.txt: user1:1234:/home/homedir1 ; user2:1234:/home/homedir2 ; user3:1234:/home/homedir3 ; user4:1234:/home/homedir4 ; The script should create an user using the... (2 Replies)
Discussion started by: marcosruiz
2 Replies

2. Shell Programming and Scripting

Creating your own Header file in awk

whether it is possible in awk to create your own header file like in C if so someone give me awk equivalent for below one $ cat foo.h int add(int a,int b) { return(a+b); } $ cat main.c #include<stdio.h> #include"foo.h" void main() { int number1=10,number2=10,number3; number3 =... (5 Replies)
Discussion started by: Akshay Hegde
5 Replies

3. UNIX for Dummies Questions & Answers

Problem in creating CSV file

Hi guys, I am not experienced with Unix, so please dont mind if the question seem to be irrelevant. I have written a simple script, that connects DB & fetches few records from a table. I wanted to get those details as file in .CSV format via mail. -I stored the query o/p in a file. -I... (6 Replies)
Discussion started by: sumitburnwal88
6 Replies

4. Shell Programming and Scripting

problem in creating execute profile file in unix

first i created a profile file(my_var.profile) which contains export my_var=20 after that i created shell scripts(my_var.sh) which contains #!/bin/bash . ./my_var.profile echo '$my_var='$my_var but when i am executing sh my_var.sh it is showing error that no such file/directory .profile.... (6 Replies)
Discussion started by: pratikjain998
6 Replies

5. Shell Programming and Scripting

problem in creating my own profile file in unix

I am new in shell scripting. currently i am using cygwin. My problem is i created a profile file in my own folder. file name is first.profile in which i gave following values to variable export a=10 now i am executing this profile file by below command ./.first.profile it executed... (4 Replies)
Discussion started by: pratikjain998
4 Replies

6. UNIX for Advanced & Expert Users

problem creating pxelinux.cfg default file

Hi All, I was trying to create pxelinux.cfg/default file in a script that I use for creating backup of bootimage. cat 2>${BACKUB_BOOTIMAGE_ERRINFO} >${pxelinux_cfg_file} <<EOF prompt 1 timeout 0 display boot.msg label restore kernel kernel append root=/dev/nfs... (0 Replies)
Discussion started by: Pkumar Sachin
0 Replies

7. Shell Programming and Scripting

Awk print to file problem

Hello, I have a file seperated with "|" I want to search the 11th field if it matches certain words change it to an empty space. I have managed to do that, but now I need it to replace the file. this is my code: awk 'BEGIN{OFS=FS="|"}$11=="to... (9 Replies)
Discussion started by: TasosARISFC
9 Replies

8. Shell Programming and Scripting

awk: creating a fixed-width single file from 2 different files

I have to create a single file from three files, Please see below for samples: day.txt 20090101 20090102 item.txt 123456789101 12345678910209 1234567891 str.txt 1 12 123 output.txt 20090101123456789101 1 0 2009010112345678910209 12 ... (2 Replies)
Discussion started by: tamahomekarasu
2 Replies

9. Shell Programming and Scripting

Creating an sql statement from a file. Problem with '

Hi, I am trying to create sql statements from a file, but I have a problem with ': This is what I do: cat filex.txt | awk -F: '{print $1,"A","and personnavn like",$5}' | sed -e "s/^/select bruker.brukernavn, person.personnavn from bruker, person where brukernavn like '/" -e "s/$/' and... (2 Replies)
Discussion started by: hannem
2 Replies

10. Shell Programming and Scripting

creating a csv file in awk

Hi All I am trying to create a csv file in the korn shell and the script segment is as follows: if then # NEED TO ADD INFO TO THE EMAIL FILE ABOUT THE DRIVE THAT'S FILLING UP echo "$drive $percent% $space "|\ awk '{printf("%d/t"|"%d/t"|"%d/t\n",... (6 Replies)
Discussion started by: Segwar
6 Replies
Login or Register to Ask a Question