Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

AWK & SED Constructs

// Various awk and sed combinations.

awk & Sed construct

View lines  500 to 505
awk 'NR >= 500 && NR <= 505'

remove blank lines
sed -e /^$/d data > filename

remove tabs :

 sed 's/^[ \t]*//' data_raw > data_raw1

search and replace words with escape:

sed -e '/\/id\//d' urls.dat > urlsnostory.dat

awk '{print $3,$2}' emp_names

awk '/AL/ {print $3,$2}' emp_names

what I used
awk '{print $1}' parsed_hrefs >> finalcut

 awk '/href\=\"(.*) / {print $2}' hrefs pinr

awk '{print $NF}' wnba -- Print last line of the code.

-----------------------
Extracting from live xml
awk '/gameId=/{print "/nugget/100_5_" substr($5,9,11)}' ts
 awk '/gamecode/{print "/nugget/100_73_" substr($2,7,10)}' nba
awk '/gamecode/{print "/nugget/100_49_" substr($2,7,9)}' mlb

----------------------------

Extracting gameIds from scores page
awk '/gamecode code=*/ {print substr($2,28,10)}' nbascores

CBK:
awk '/gamecode code=*/ {print substr($2,7,12)}' cbk

Extracting headers
awk '{print $1 " " $2 " " $3 " <img src=\"http://jqa.foxsports.com/fe/img/Writers/header/" $3 ".jpg\"> " "<br>"}' authwids 

Field Seperator
awk -F\\ '{print $6}' logos  [ The \\ escape is added ]

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets