1830226 Members
1613 Online
109999 Solutions
New Discussion

Awk

 
SOLVED
Go to solution
Vanquish
Occasional Advisor

Awk

Hi i am trying to get output as
temp
123
lib
resd
com
hp
res
email
html.txt

echo temp/123/lib/resd/com/hp/res/app/email/html.txt| awk '{print substr($0,1)}'

I did try a lot with substr, i tried cut and split too.
echo temp/123/lib/resd/com/hp/res/app/email/html.txt|cut -d / -f1

echo temp/123/lib/resd/com/hp/res/app/email/html.txt|awk '{split('$0',a,"/"); print a[1]}'

Thanks
4 REPLIES 4
K.C. Chan
Trusted Contributor

Re: Awk

awk -F"/" {print $1,"\n",$2,"\n", ...}'
Reputation of a thousand years can be determined by the conduct of an hour
Stuart Browne
Honored Contributor

Re: Awk

So basically you want to replace all /'s with a line feed. 'tr' is the tool for you:

echo temp/123/lib/resd/com/hp/res/app/email/html.txt | tr '/' '\n'

This will put each part of the path on a separate line.

That being said, what's your goal of doing this? If you want to just get the file-name off the end, then just use the 'basename' command.
One long-haired git at your service...
Muthukumar_5
Honored Contributor
Solution

Re: Awk

hai,

To do this, use

1. printf "$(echo temp/123/lib/resd/com/hp/res/app/email/html.txt | sed -e 's/\//\\n/g')"

2. echo temp/123/lib/resd/com/hp/res/app/email/html.txt | sed -e 's/\//\
/g'

3. echo temp/123/lib/resd/com/hp/res/app/email/html.txt| awk -F '/' '{
for ( i=1; i<=NF; i++) print $i }'

Regards,
Muthukumar.
Easy to suggest when don't know about the problem!
Francisco J. Soler
Honored Contributor

Re: Awk

Hi,

like K.C. Chan but with all fields:

echo temp/123/lib/resd/com/hp/res/app/email/html.txt | awk -F'/' '{for (i=1;i<=NF;i++) print $i}'

Frank.

Linux?. Yes, of course.