Computing.Net > Forums > Unix > Extracting a part of text using AWK

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Extracting a part of text using AWK

Reply to Message Icon

Name: raptor3624
Date: April 12, 2007 at 06:08:26 Pacific
OS: Win XP
CPU/Ram: 2 gig
Product: AMD
Comment:

I have a text file which runs like as below-

-f /data/feed/cj/2007-03-09/10273657-Forzieri_com_Europe.txt -p CJFeedProcessor -i generic -h 0
-f /data/feed/cj/2007-03-09/10362510-SOFT_SURROUNDINGS.txt -p CJFeedProcessor -i generic -h 855
-f /data/feed/cj/2007-03-09/10273670-Flowers_Fast.txt -p CJFeedProcessor -i generic -h 298
-f /data/feed/cj/2007-03-09/10273680-1_Stop_Florists.txt -p CJFeedProcessor -i generic -h 335
-f /data/feed/cj/2007-03-09/10364982-Wissota_Trader.txt -p CJFeedProcessor -i generic -h 708

I would like to extract only the name(after the date i.e "10273657-Forzieri_com_Europe.txt" and the SKU count at the end.I want to do this with AWK.

SO basically,I want to extract only 2 parts of a text file.Could any one of you help me out?Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: thepubba1
Date: April 17, 2007 at 12:51:13 Pacific
Reply:

I'm too lazy to write an awk statement so I did what you wanted with a shell script. I put your data into a file called junk.data


#!/bin/ksh

parseIt() {

echo "${2##*/}\t$8"

}

exec 3<junk.data
while read -r -u3 line
do
parseIt $line
done

Jerry


0

Response Number 2
Name: ghostdog
Date: April 21, 2007 at 21:25:53 Pacific
Reply:

here's the awk script
[code]
awk '{ n = split($2, array , "/");print array[n] " " $NF }' "file"
[/code]


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Extracting a part of text using AWK

Find the day of week using AWK www.computing.net/answers/unix/find-the-day-of-week-using-awk/5243.html

Sed - replace block of text - but h www.computing.net/answers/unix/sed-replace-block-of-text-but-h/7063.html

replacing occurances of text www.computing.net/answers/unix/replacing-occurances-of-text/4333.html