LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 05-22-2012, 10:41 AM   #1
udiubu
Member
 
Registered: Oct 2011
Posts: 54

Rep: Reputation: Disabled
print first 2 characters + second column


Dear all,

I guess a very simple one:

I have a long matrix with 5 columns. It looks like this:

alpha 3 xxx xxx xxx
beta 23 xx xxx xx
gamma 24 xx xxx xxx

I need the following output, in which the first two characters from column 1 are selected, plus the entire column 2:

al 3
be 23
ga 24

a code like cut -c 1-2 would just solve the first column, but not the second.

Any suggestion is highly appreciated!

Sincerely,

Udiubu
 
Old 05-22-2012, 11:22 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,490

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
A simple awk one-liner should do the trick:
Code:
awk '{print substr($1,1,2),$2}' file
 
1 members found this post helpful.
Old 05-22-2012, 12:48 PM   #3
udiubu
Member
 
Registered: Oct 2011
Posts: 54

Original Poster
Rep: Reputation: Disabled
Thanks that works perfectly!

Best
 
  


Reply

Tags
character, column, cut, print


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] Speeding up a script to count number of repeat characters in each column tweed08 Linux - Newbie 4 03-21-2012 09:15 AM
compare second column of a file then print the first column of it in a ne fil if true java_girl Linux - Newbie 2 03-16-2012 04:50 AM
[SOLVED] AWK: print all fields in one column cristalp Programming 3 03-14-2012 11:43 AM
How do I get ls to print column headings? Belton222 Linux - Newbie 2 10-30-2011 01:13 AM
[SOLVED] search a string and print column vikas027 Programming 6 03-14-2010 09:20 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration