LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 02: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, 02: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, 02:39 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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, 03: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, 04:03 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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, 04: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, 02:50 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 02:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration