LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-08-2011, 01:10 PM   #1
verse123
LQ Newbie
 
Registered: Oct 2011
Posts: 19

Rep: Reputation: Disabled
creating columns with awk?


Hi guys,

Does anyone know how to separate a column into two if a criteria is met using awk?

For example, how could one separate col1 into two columns if ":" is present while removing ":" in the output

col1 col2
T:3442 435
R:324 45560

this should look like this:
col1 col2 col3
T 3442 435
R 324 45560
 
Old 11-08-2011, 01:17 PM   #2
verse123
LQ Newbie
 
Registered: Oct 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Nevermind... I figured it out
 
Old 11-08-2011, 01:39 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Now if you posted your solution others who search for the same
issue would actually be able to benefit from it ...



Cheers,
Tink
 
Old 11-08-2011, 02:29 PM   #4
verse123
LQ Newbie
 
Registered: Oct 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
instead of awk, a simple sed would work:

Code:
 sed 's/T://g' input > output
in my case this was going to excel so I had saved the "T:" initially in a separate column so I realized I didn't really need it. This sed command will remove T: and just print out the following numbers without it.
 
Old 11-08-2011, 03:03 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by verse123 View Post
instead of awk, a simple sed would work:

Code:
 sed 's/T://g' input > output
in my case this was going to excel so I had saved the "T:" initially in a separate column so I realized I didn't really need it. This sed command will remove T: and just print out the following numbers without it.

Interesting :)

This doesn't do what you first described as what you want/need.
That would have been:
Code:
sed 's/:/ /g' input > output

Cheers,
Tink
 
Old 11-08-2011, 03:21 PM   #6
verse123
LQ Newbie
 
Registered: Oct 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
it doesn't does it but since I had it already in excel, things worked out. Thanks for the tip though.
 
Old 11-09-2011, 01:50 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
And what about 'R:'?
 
  


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] AWK: add columns while keep format for other columns cristalp Programming 3 10-13-2011 06:14 AM
extracting columns with awk gav251 Programming 7 03-10-2011 08:40 AM
AWK - combining multiple columns AlexYZ Programming 5 02-24-2010 07:09 AM
Using awk to switch columns bioinformatics_guy Linux - Newbie 3 10-30-2008 09:50 AM
Moving columns with sed or awk? btm Linux - Newbie 4 09-27-2007 02:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:39 PM.

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