Operating System - HP-UX
1829735 Members
2059 Online
109992 Solutions
New Discussion

cut command - specifying multiple delimiters

 
SOLVED
Go to solution
jon2
Advisor

Re: cut command - specifying multiple delimiters

Peter said
"if you like a solution using shell features only (I did this in ksh): "

Your script starts with "#!/bin/sh"

I suspect this is the problem with your latest post.

BTW did the "read VAR1" work okay in my suggestion. It is odd if it works in mine but not Harrys.
Peter Nikitka
Honored Contributor

Re: cut command - specifying multiple delimiters

Hi Danny,

I just checked:
/bin/sh
a=b.c
echo ${a#*.}

results in 'c' - so the string operators work in the posix shell as well.
Nevertheless:
- Flag your script with
#!/usr/bin/ksh -xe
It will stop at rhe first error and trace the commands.
- check for unprintable characters (like ^M).

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Nagendra Prasath
New Member

Re: cut command - specifying multiple delimiters

Hi Danny,
I too don have good knowledge, anyway see this code..it'll work.
since i've used only the coloumn number don change the coloumn number with any space.

copy your line "A20051109.0215-0230_SubNetwork=ONRM_RootMo,SubNetwork=SNTDCAUJRNC002,MeContext=SNTDCAUJRNC002_statsfile.xml"
in a file say file1
then do chmod 777 file1
then open a file say solution1.txt and paste the below lines

one=`cat file1 | cut '-c1-9'`
echo "1)$one"
two=`cat file1 | cut '-c11-14'`
echo "2)$two"
three=`cat file1 | cut '-c16-19'`
echo "3)$three"
four=`cat file1 | cut '-c21-93'`
echo "4)$four"
five=`cat file1 | cut '-c95-103'`
echo "5)$five"
six=`cat file1 | cut '-c105-107'`
echo "6)$six"

save and quit
chmod 777 solution1.txt
do ./solution1.txt
it'll give the file in that format.


Also you can alter the code as you require
If you use sed, everything can be finished in one
line.

:)
Prasath