LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2011, 07:12 PM   #1
mad_penguin
Member
 
Registered: Mar 2008
Posts: 69

Rep: Reputation: 15
sed/awk help on text


Hi gents,

I have this text file with exactly 3 columns like this:

sometext sometextsometext sometext
sometext sometext sometext
sometext sometextsometextsometext sometext

The request will be to 'fix' the third column. I mean how can I bring the last column to the second one?
In fact better will be to know how could I format this text doc so that last column will be vertically alligned (notice that on the second column the rows are not equal )

Awaiting your suggestions.

Cheers.
 
Old 09-20-2011, 09:01 PM   #2
crulat
Member
 
Registered: Sep 2011
Location: BeiJing China
Posts: 34

Rep: Reputation: Disabled
awk '{print $1,$3,$2}'
 
Old 09-20-2011, 09:38 PM   #3
mad_penguin
Member
 
Registered: Mar 2008
Posts: 69

Original Poster
Rep: Reputation: 15
Thank you Crulat!
 
Old 09-21-2011, 07:53 AM   #4
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
'column -t' formats text into columns
http://linux.die.net/man/1/column
Code:
echo '
sometext sometextsometext sometext
sometext sometext sometext
sometext sometextsometextsometext sometext' | column -t

sometext  sometextsometext          sometext
sometext  sometext                  sometext
sometext  sometextsometextsometext  sometext
 
Old 09-21-2011, 08:57 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
OT: @crulat - I keep meaning to mention that the indirect in your Fibonacci is an added extra that is not required:

Code:
Fibonacci(){ local m=$1;(( m == 1 || m == 2 )) && echo $((m-1)) || echo $(($(Fibonacci $((m-1)))+$(Fibonacci $((m-2)))));};Fibonacci $1
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Append text with AWK or SED? LostChild1 Linux - Newbie 6 03-20-2010 08:46 AM
translating text with awk or sed mek Programming 5 11-13-2009 07:57 AM
Text substitution and processing with sed and awk shanecraddock@gmail.com Linux - Newbie 1 12-18-2008 11:34 AM
parsing text using sed/awk or similar??? freeindy Programming 5 07-24-2008 04:04 AM
awk/sed to grep the text ahpin Linux - Software 3 10-17-2007 12:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration