To print the 1st column using sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers To print the 1st column using sed
# 1  
Old 07-06-2011
To print the 1st column using sed

Hi I have an output which looks like :
Code:
XXXXXX         XXXX           XXXXXXXX            XXXXXXXXXXXXXX
XXXXXX         XXXX           XXXXXXXX            XXXXXXXXXXXXXX
.....
.....
.....

Each X out there might be an alphabet/digit.

I need to print the 1st column from this output using sed.
i have tried :
Code:
sed ' s_\(.*\) \(.*\) \(.*\) \(.*\)_\1_' filename

but this works only for a single spacing between the columns. How do I check for many spaces/tab ???

Last edited by Franklin52; 07-07-2011 at 03:34 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 07-06-2011
Juste remove everything after (and including) the first space found

Code:
sed 's/ .*//' input

This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 07-07-2011
this dint work out for me....I get all the columns when i use this code
Code:
sed 's/ .*//' input


Last edited by Franklin52; 07-07-2011 at 03:34 PM.. Reason: Please use code tags for data and code samples, thank you
win4luv
# 4  
Old 07-07-2011
Quote:
Originally Posted by win4luv
this dint work out for me....I get all the columns when i use this code

sed 's/ .*//' input

Maybe they are tab separated instead of space separated, just change the space before the dot into a tab, otherwise you can give a try to

Code:
tr '\t' ' ' <yourfile | sed 's/ .*//'

# 5  
Old 07-08-2011
you are simply aweseomeSmilie....Also lets say, if i need to pull 3 & 4 or any random selection of the columns how do i go abt doing it? Also can you please suggest some good unix books
appreciate your help.
win4luv
# 6  
Old 07-08-2011
To print only column 3 & 4 in a tab separated file:

Code:
awk -F"\t" '{print $3 FS $4}' yourfile

Regarding good Unix books, just go here
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to print nth till last column of ls output using sed

I wish to print first, third and sixth till the last column from the output of ls command ls -ltr /app/deploy.yml -rw-rw-r-- 1 user1 dba 27342 Aug 28 10:17 /app/deploy.yml Desired Output: Below command gives me the desired output. ls -ltr /app/deploy.yml | awk '{$2=$4=$5=""; print... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. UNIX for Beginners Questions & Answers

Compare 1st column from 2 file and if match print line from 1st file and append column 7 from 2nd

hi I have 2 file with more than 10 columns for both 1st file apple,0,0,0...... orange,1,2,3..... mango,2,4,5..... 2nd file apple,2,3,4,5,6,7... orange,2,3,4,5,6,8... watermerlon,2,3,4,5,6,abc... mango,5,6,7,4,6,def.... (1 Reply)
Discussion started by: tententen
1 Replies

3. Linux

Print the 1st column and the value in 2nd or 3rd column if that is different from the values in 1st

I have file that looks like this, DIP-17571N|refseq:NP_651151 DIP-17460N|refseq:NP_511165|uniprotkb:P45890 DIP-17571N|refseq:NP_651151 DIP-19241N|refseq:NP_524261 DIP-19241N|refseq:NP_524261 DIP-17151N|refseq:NP_524316|uniprotkb:O16797 DIP-19588N|refseq:NP_731165 ... (2 Replies)
Discussion started by: Syeda Sumayya
2 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

comparing column of two different files and print the column from in order of 2nd file

Hi friends, My file is like: Second file is : I need to print the rows present in file one, but in order present in second file....I used while read gh;do awk ' $1=="' $gh'" {print >> FILENAME"output"} ' cat listoffirstfile done < secondfile but the output I am... (14 Replies)
Discussion started by: CAch
14 Replies

6. Shell Programming and Scripting

AWK/SED print if 2nd character in a column is greater than 0

We have an access log where column 8 displays the time in seconds like below: Tj8nQAoNgwsAABov9cIAAAFL - 10.13.131.80 - - (0) - "GET /aaaaa/bbbb/bbbb where column 8 is printed (0). We are trying to find how many entries are there that has column 8 greater than 0. Remember $8 is (0) and not... (5 Replies)
Discussion started by: spacemtn5
5 Replies

7. Shell Programming and Scripting

Using sed on 1st column of tab delimited file

Hi all, I'm new to Unix and work primarily in bioinformatics. I am in need of a script which will allow me to replace "1" with "chr1" in only the first column of a file which looks like such: 1 10327 rs112750067 T C . PASS ASP;RSPOS=10327;... (4 Replies)
Discussion started by: Hkins552
4 Replies

8. Shell Programming and Scripting

sed/awk to update 1st column if condition met

Hi, I am trying to update the 1st column of a file but only if it contains a char here is an example of my file 1111aaa 9999 textaaa 22222bbb 9999 textbbb 3333 9999 textccc 444ddd 9999 textddd i would like the output to remove any characters () from... (5 Replies)
Discussion started by: plennon
5 Replies

9. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

10. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies
Login or Register to Ask a Question