Register
It is currently Mon Sep 22, 2014 6:13 am

resize ascii file


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Nov 16, 2010 3:18 am   

Joined: Tue Nov 16, 2010 3:14 am
Posts: 1
hi,
I have a txt file with a sequence of values organized in "n" rows and "m" coloumns. I want this values to be organised in "t" coloumns (t is different by m) is it possible with a bash command? thank u for your attention.

Luca


Top
 Profile  
 PostPosted: Tue Nov 16, 2010 4:14 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
I do not get it. Do you want to remove some columns? You can try
Code:
cut -f1,3,4
Or do you have a sequence of values (accidentaly organised in a table) and you want to re-organise them into t columns? Then you need more than just a command, for example something like this:
Code:
sed 's/\t/\n/g' | while read n ; do
  if ((count++%t == t-1)) ; then
    echo "$n"
  else
    echo -n "$n"$'\t'
  fi
done

The code assumes that the table uses the tab as a separator and that $t is set to the number of output columns.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP