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

cut command??? 1

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
0
0
US
Hi...
I have a tab delimited file that has three fields. It looks like this:

1111 14A 1111
2222 7C 2222
3333 11B 3333
4444 99X 4444

I need to write a command that will "cut" three bytes from the second field (cutting spaces if there is no data in the third byte), outputting them to newfile.
I've tried, &quot;cut -f2 <infile> > <outfile>&quot;, and that works, except it doesn't take three bytes from the second field containing '7C'. In other words, it cuts '7C', instead of '7C '. Know what I mean???
Once again, any help would be greatly appreciated. Thanks!
 
Have you tried looking up possibilties using sed or awk?
 
nawk '{printf(&quot;[%-3s]\n&quot;, $2);}' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
or something like that with sed:

sed -e 's/^\([^ ][^ ]*\)[ ][ ]*\(...\).*/[\2]/g' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top