Understanding Awk and Cat


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Understanding Awk and Cat
# 1  
Old 07-27-2009
Understanding Awk and Cat

Hi Guys,

I was recently come across some code to hopefully learn a little bit about putting Shell commands into PHP application to run on a Linux server. However, I don't understand the command AT ALL... and was wondering if anyone can interpret it:

Code:
cat userIDs.dat | awk '{s=s+1; if (s==$end) print $0; if (s > $start && s < $end) printf \"%s,\", $0}' > path/to/file/to/store/in/IDS.file


It doesn't seem to do anything, but I may have put an error in there, when making it applicable to my directories etc. I have no clue!


Any light you guys can shed on this would be great!


Thank you,
Jordan
# 2  
Old 07-27-2009
awk won't understand the shell variables.
you have to tell awk that those are shell variables.

so in your case "$end", "$start" etc are not being replaced by the actual values.

user double quotes or -v flag.

Code:
awk -v START="$start" -v END="$end" '{s=s+1; if (s==END) print $0; if (s > START && s < END) printf \"%s,\", $0}' > path/to/file/to/store/in/IDS.file

if you are facing problem related to your requirement, then please post your sample "IDS.file" and require output ( conditions).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Understanding awk 'expansion'

Heyas Recently i wanted to help someone with an awk script, but the end-script didnt work as expected. He wanted, if HOME was empty, to get the HOME of the current USER from /etc/passwd. At first i tried hardcoded with root: awk -F: '/^root/ {print $6}' /etc/passwd As that worked, i've... (4 Replies)
Discussion started by: sea
4 Replies

2. Shell Programming and Scripting

awk : Need Help in Understanding a command

Hello I am working on a Change request and Stuck at a point. The below awk command is used in the function. float_test ( ) { echo | awk 'END { exit ( !( '"$1"')); }' } I understand that awk 'END' is used to add one line at the end and exit is used to end the script with an error... (4 Replies)
Discussion started by: rahul2662
4 Replies

3. UNIX for Dummies Questions & Answers

Understanding awk

I found this on an awk site and would like to know what it does: /CARS/{x="";next} {if(x)print x;x=$0} END{if(x)print x}' Does it mean if it finds the word cars it skips that line and then prints the next one? (4 Replies)
Discussion started by: newbie2010
4 Replies

4. Shell Programming and Scripting

Help in Understanding awk if ( F ) syntax -

Hi Experts, I was looking at the below link, for finding words next to it, And unable to understand this syntax: Can any one please explain , what is meaning of this code: if ( F ) s = s ? s OFS $i : $i from:... (4 Replies)
Discussion started by: rveri
4 Replies

5. Shell Programming and Scripting

Help in understanding awk expression

Hi, Could somebody help me in understanding the following awk expression: awk -v n="POINT" '/%/{print $0 "\n" n ;next}1' < file name Thanks, Arun (6 Replies)
Discussion started by: arun_maffy
6 Replies

6. UNIX for Dummies Questions & Answers

awk+cat

Hi, I am doing this: ll -tr | awk '{print $6, $7, $8, $9}' the result is: Dec 30 2008 text1.txt Mar 4 2009 text2.txt Apr 10 2009 text3.txt and now I want to show the content of $9 using below: ll -tr | awk '{print $6, $7, $8, $9}' ; '{cat $9}' (25 Replies)
Discussion started by: messi777
25 Replies

7. UNIX for Advanced & Expert Users

understanding awk in this script

i am analyzing a query written by another developer ,need to understand part of script am looking at a code ..and it converts comma files to pipe delimited and also takes away quotes from any columns, source field format: 2510,"Debbie",NewYork changes to target: 2510|Debbie|NewYork ... (1 Reply)
Discussion started by: coolrock
1 Replies

8. Shell Programming and Scripting

Using cat and awk.......

Im trying to use cat and awk to calculate the total space, then display it using the print command. But something in my script is not correct? cat | awk '{print$1}' | sort -n | grep -v used | awk '{sum += $1} END { p rint sum;}' ??? Any help would be greatly appreciated!! (10 Replies)
Discussion started by: bigben1220
10 Replies

9. Shell Programming and Scripting

Need help on understanding the Shell and AWK scripts

Hello Friends, I am new to the scripting & have to analyze bunch of regular production scripts. It has .ksh which calls on the .awk script having many functions I need to understand and debug the scripts ASAP Can anybody please let me know as how can I debug, I want to see the flow of code... (3 Replies)
Discussion started by: amberj123
3 Replies

10. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies
Login or Register to Ask a Question