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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cutting the last 2/3 fields on a line

Status
Not open for further replies.

octar

Technical User
Oct 21, 2002
28
AU
Hi, So far I have managed to get the following but I need to go one more level as detailed below:

The file reads:

$CMDE "/*" &
$CMDE "/usr/*" >>$LOG
$CMDE "/var/*" >>$LOG &
$CMDE "/tmp/*" >>$LOG
$CMDE "/home/*" >>$LOG &

Using -> awk {'print $2'} | cut -c2-20 <- I can get

/*&quot;
/usr/*&quot;
/var/*&quot;
/tmp/*&quot;
/home/*&quot;

Now, how do I manage to get the following???
ie. cutting the last 2/3 fields on each line?

/
/usr
/var
/tmp
/home

thanks in advance
 
Try

awk '{j = length($2)-4; if (j<1) j=1; print substr($2,2,j)}' infile CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top