1833437 Members
3171 Online
110052 Solutions
New Discussion

cut in a script

 
ROSS HANSON
Regular Advisor

cut in a script

Hello
I am trying to write a script that gives me a swlist, and other
things, I am trying to cut out
some "tabs" How do I cut out tabs
using the cut command???
Ross Hanson
6 REPLIES 6
Rodney Hills
Honored Contributor

Re: cut in a script

If you use the following "awk" command-

swlist | awk '/^ /{print $1 ":" $2 ":" $3}'

This will replace the tabs with ":".

Hope this helps.

-- Rod Hills
There be dragons...
harry d brown jr
Honored Contributor

Re: cut in a script

try this:

swlist | cut -d"Ctrl-vCtrli" -f2

Ctrl-v and Ctrl-i should put a tab in "cut" as a seperator.

live free or die
harry
Live Free or Die
Peter Gillis
Super Advisor

Re: cut in a script

Hi,
I just tried:
swlist|cut -f1
this gave me just col. 1.
Looked in 'cut' man pages - tab delimiter is the default, so i figure no need to actually specify it, when used with -f.

see ya.
Maria
Nick Wickens
Respected Contributor

Re: cut in a script

I often find its usefull to translate the tabs into spaces and then remove repeated spaces using this command string -

tr '\011' ' ' | tr -s " "

Or you could simply change successive tabs into one tab with tr -s "\011"
Hats ? We don't need no stinkin' hats !!
Mark van Hassel
Respected Contributor

Re: cut in a script

Hi,

Sometimes its difficult using awk to differentiate between the colums beacuse of the difference in the amounts of tabs, spaces etc. You can use the folowing:

swlist -l product -a size -a install_date -a description | while read SIZE DATE DESC
do
...
done

This way you can seperate the different columns, just have description as the last column.

HtH,
Mark
The surest sign that life exists elsewhere in the universe is that none of it has tried to contact us
H.Merijn Brand (procura
Honored Contributor

Re: cut in a script

Expanding tabs to spaces *keeping* the format (column-wise) can be done with the command 'expand'

cut -f1 works on tabs, so - as Maria already said - should just give what you need.

If you have `expand'ed your tabs, you can switch to

cut -c1-9 to get the first nine characters of each line (or -c16-55 for columns 16 though 55, see man cut), including the white space

cut also accepts a -d option to specify the delimiter

cut -d\ -f3 ...
Enjoy, Have FUN! H.Merijn