Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk example - conditional print

Status
Not open for further replies.

tomd8

MIS
Jun 23, 1999
1
US
I am looking for an example of an awk statement performing a conditional print or what is wrong with this syntax:<br>
cat $file ¦ awk '{if ($2="Date") print " " $1 " " $2 else print $1}'
 
awk '$2 == "Date" { print " " $1,$2} <br>
$2 != "Date" { print $1} ' $FILE<br>
<br>
or<br>
<br>
awk '$2 == "Date" { printf " %s %s\n",$1,$2}<br>
$2 != "Date" { printf "%s\n",$1} ' $FILE
 
What would be the command to sort a specific syntax in a line but also that whole column? for example:

/wow/media/now
/wow/media/help

I want to sort just /now and /help.

-M
 
umm ... well i've done this before with numbers in the wrong order ... i can never seem to work out the syntax of sort ...

the text you want sorted is in <file>

cat <file> | awk '{ numsplit=split($0,spl,&quot;/&quot;); print spl[numsplit]&quot;\t&quot;$0; }' | sort | awk '{ print substr($0,index($0,&quot;\t&quot;)+1); }'

seems to work :)
 
Hi both,

Have a look at the &quot;General UNIX discussion Forum&quot; if you like, lots of other UNIX people there. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top