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!

Grep or Cut 1

Status
Not open for further replies.

xyz786

IS-IT--Management
Apr 5, 2006
45
US
Hello,
How can i get the output value 5424 from a a file containing the line 339 (5424 megabytes) using grep or cut or anything.
 
cat filename.txt | grep "^339 (" | cut -c 6-9

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Personally I would use something like:

[tt]grep 339 yourfilename | cut -d '(' -f 2 | cut -d ' ' -f 1[/tt]

That way it would also work if it was 5424 megabytes, 54242424 megabytes or 5 megabytes.

Annihilannic.
 
Thanks Guys for your quick responses.

 
I've got to get out of the habit of using cat.......

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
But I like cats!
Code:
cat < x.dat | cat | grep "^339 (" | cat | cut -c 6-9 | cat | cat | cat | cat
[bigsmile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top