Help with Bash script - set, awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Bash script - set, awk
# 8  
Old 07-13-2009
Sorry for buggin u..
I still get the same error

$ echo $pat1
Processing
$ echo $pat2
aaaa
$ cat test
asdsf

aaaa

adsajd

asda



Processing



sdfdkjf

aaaa

dflkjd

dfjkhdk


$ awk '/p1/{f=1} f && /p2/{print;end}' p1=$pat1 p2=$pat2 test
awk: syntax error near line 1
awk: bailing out near line 1
$

---------- Post updated at 08:23 AM ---------- Previous update was at 08:20 AM ----------

Sorry, I dont get the error, But I dont get the desired output


$ echo $pat1
Processing
$ echo $pat2
aaaa
$ cat test
asdsf

aaaa

adsajd

asda



Processing



sdfdkjf

aaaa

dflkjd

dfjkhdk


$ nawk '/p1/{f=1} f && /p2/{print;end}' p1=$pat1 p2=$pat2 test
$ /usr/xpg4/bin/awk '/p1/{f=1} f && /p2/{print;end}' p1=$pat1 p2=$pat2 test
# 9  
Old 07-13-2009
I'm sorry, the code should be:

Code:
nawk '$0 ~ p1{f=1} f && $0 ~ p2{print;end}' p1=$pat1 p2=$pat2 test.dat

# 10  
Old 07-13-2009
Hi Thanks a lot.
$ /usr/xpg4/bin/awk '$0 ~ p1{f=1} f && $0 ~ p2{print;end}' p1=$pat1 p2=$pat2 subha
input file "Started"aaaa
aaaa
$

I get " input file "Started" " in the output. Can we omit this and just print aaaa??

Thanks for your help!
# 11  
Old 07-13-2009
Strange..try this, assuming subha is the filename:

Code:
/usr/xpg4/bin/awk -v p1=$pat1 -v p2=$pat2 '$0 ~ p1{f=1} f && $0 ~ p2{print;end}' subha

# 12  
Old 07-13-2009
When I run the command, it prompts as below...
$ /usr/xpg4/bin/awk -v p1=$pat1 -v p2=$pat2 '$0 ~ p1{f=1} f && $0 ~ p2{print;end}' file
input file "-v"$ Started
ksh: Started: not found

I am not sure either..
# 13  
Old 07-13-2009
I don't know what's wrong, the code seems to be correct, post a part of the original file and the desired output within code tags.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Set password in bash script without manual entry-Solaris 10

Hi I have a root script which is setting up user and his dirs and so on. After I create user and set up all the necessary I have to manually set user password. I try all possible ways what google find me and nothing works for me. If maybe one of you have a solution for my problem it will be... (1 Reply)
Discussion started by: Jaffakeks
1 Replies

2. Shell Programming and Scripting

Bash/awk script problem

Hi, I have 100 files containing different values in single column, I want to split those files in two separate files (file2 and file3) based on average value of first column of each file, for those files I am working on the following script #bin/bash for memb in $(seq 1 100) do awk... (4 Replies)
Discussion started by: dsp80
4 Replies

3. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

4. Shell Programming and Scripting

Bash script set command to a variable

Hi, Will following set up work in bash script? I've got errors if assigning following binary command to a variable. But on the other hand, COMMAND="ls" works. Any explanation please? How can I assign binary command to a variable COMMAND then I can just call ${COMMAND}? COMMAND="rsync"... (3 Replies)
Discussion started by: hce
3 Replies

5. Shell Programming and Scripting

awk script to filter the numbers which are around the set value

Hi All, I have one sensor output(over the same) for a set value of 20. Time(in Sec), Data 1, 16 2, 20 3, 24 4, 22 5, 21 6, 20 7, 19.5 8, 20 9, 20.5 10, 20 11, 20 12, 19.5 Here we can see like after 5 sec of time the data value reaches to 20+-0.5 range. So I... (7 Replies)
Discussion started by: ks_reddy
7 Replies

6. Shell Programming and Scripting

AWK/Bash script

I would like to write a script to extend this command to a general case: BEGIN {s_0=0;n_0=0}{n_0++;s_0+=($51-$1)^2}END {print sqrt(s_0/n_0)} i.e. so that BEGIN {s_0=0;n_0=0}{n_0++;s_0+=($51-$1)^2}END {print sqrt(s_0/n_0)} BEGIN {s_1=0;n_1=0}{n_1++;s_1+=($51-$2)^2}END {print... (3 Replies)
Discussion started by: chrisjorg
3 Replies

7. Shell Programming and Scripting

Help: How to convert this bash+awk script in awk script only?

This is the final first release of the dynamic menu generator for pekwm (WM). #!/bin/bash function param_val { awk "/^${1}=/{gsub(/^${1}="'/,""); print; exit}' $2 } echo "Dynamic {" for CF in `ls -c1 /usr/share/applications/*.desktop` do name=$(param_val Name $CF) ... (3 Replies)
Discussion started by: alexscript
3 Replies

8. Shell Programming and Scripting

Using AWK in a bash script

So I am a newbie obviously but I need some help. I am trying to run a script to check that the number of fields in a database is equal to 4, if not they should try again and run an appropriate database file. The fields are separated by a semi colon. I've tried a lot of things, this what I'm... (3 Replies)
Discussion started by: mb001
3 Replies

9. Shell Programming and Scripting

bash variable (set via awk+sed) not working as expected

Hi! Been working on a script and I've been having a problem. I've finally narrowed it down to this variable I'm setting: servername=$(awk -v FS=\/ '{ print $7 } blah.txt | sed 's\/./-/g' | awk -v FS=\- '{print $1}')" This will essentially pare down a line like this: ... (7 Replies)
Discussion started by: creativedynamo
7 Replies
Login or Register to Ask a Question