If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > column string truncation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-28-03, 17:37
jeremas jeremas is offline
Registered User
 
Join Date: May 2002
Posts: 73
column string truncation

Hello

I have a file with next columns:

abscv dfghs tyhh I012453637felfwe.WAV
cvdbb dfghs fggh I01234255363678.WAV


could be possible using awk the truncation/spliting the fourth column in two, e.g:

I012453637felfwe.WAV ---> I012453 637felfwe.WAV
I01234255363678.WAV ----> I012342 55363678.WAV

Thanks.
Reply With Quote
  #2 (permalink)  
Old 11-29-03, 14:45
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Try this

COLUMNS="abscf dfghs tyyh I012453637felwe.WAV"
DUMMY=`echo $COLUMNS | awk '{
print $1
print $2
print $3
dummy1=substr($4, 1, 7)
dummy2=substr($4, 8)
print dummy1
print dummy2
}'`
echo $DUMMY

for i in $DUMMY
do
echo $i
done

or try this :
here you get a new file with new columns :

IFS="@"; for a in `cat /usr/mydir/myfile.txt`
do
echo $a | awk '{
dummy1=substr($4, 1, 7)
dummy2=substr($4, 8)
print $1" "$2" "$3" "dummy1" "dummy2 >> "/usr/mydir/myfile.new"
}'
done

Peter F.
__________________
Greetings from germany
Peter F.

Last edited by fla5do; 11-29-03 at 15:42.
Reply With Quote
  #3 (permalink)  
Old 12-01-03, 05:15
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
This should do it...

awk '{print $1, $2, $3, substr($4,1,7), substr($4,8)}' yourFile > newFile
Reply With Quote
  #4 (permalink)  
Old 12-01-03, 11:42
jeremas jeremas is offline
Registered User
 
Join Date: May 2002
Posts: 73
Column truncation

Thanks guys both options work pretty well.

Regards,
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On