reducing the number of characters in a column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers reducing the number of characters in a column
# 1  
Old 08-21-2010
reducing the number of characters in a column

Hi,
I would like to take the first column of a bunch of lines and take only the 6th through 15th characters. The first column are not regular.


Code:
gbAY277147.1Ptv3.T1469	CTTGAACAT
gbAY277149.1Ptro3.T1469	CTTGAACAT
gbAY287891.1Hs3.T1469	CTTGAACATTTGC

into

Code:
7147.1Ptv3 	CTTGAACAT
7149.1Ptro	CTTGAACAT
7891.1Hs3.	CTTGAACATTTGC


Thanks!!!

Mikey

Last edited by Scott; 08-21-2010 at 11:59 PM.. Reason: Please use code tags
# 2  
Old 08-21-2010
Hi.

Try:

Code:
$ awk '$1=substr($1, 7, 10)' file1
7147.1Ptv3 CTTGAACAT
7149.1Ptro CTTGAACAT
7891.1Hs3. CTTGAACATTTGC

(according to your output, you've taken characters 7 thru 16...)
This User Gave Thanks to Scott For This Post:
# 3  
Old 08-22-2010
Perfect!!!
Thanks!
# 4  
Old 10-16-2010
Quote:
Originally Posted by scottn
Hi.

Try:

Code:
$ awk '$1=substr($1, 7, 10)' file1
7147.1Ptv3 CTTGAACAT
7149.1Ptro CTTGAACAT
7891.1Hs3. CTTGAACATTTGC

(according to your output, you've taken characters 7 thru 16...)
Nice.
Can you do it with sed?
# 5  
Old 10-17-2010
Code:
sed 's/^......//;s/\(..........\)\(.[^ \t]*\)\(.*\)/\1\3/' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print column number while ignoring alpha characters

I have the following script that will print column 4 ("25") when column 1 contains "123". However, I need to ignore the alpha characters that are contained in the input file. If I were to ignore the characters my output would be column 3. What is the best way to print my column of interest... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

2. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

3. Shell Programming and Scripting

Split column data if the table has n number of column's

please write a shell script Table -------------------------- 1 2 3 a b c 3 4 5 c d e 7 8 9 f g h Output should be like this --------------- 1 2 3 3 4 5 7 8 9 a b c c d e f g h (1 Reply)
Discussion started by: Priti2277
1 Replies

4. Shell Programming and Scripting

Help with compare two column and print out column with smallest number

Input file : 5 20 500 2 20 41 41 0 23 1 Desired output : 5 2 20 0 1 By comparing column 1 and 2 in each line, I hope can print out the column with smallest number. I did try the following code, but it don't look good :( (2 Replies)
Discussion started by: perl_beginner
2 Replies

5. Shell Programming and Scripting

Remove the first character from the fourth column only if the column has four characters

I have a file as follows ATOM 5181 N AMET K 406 12.440 6.552 25.691 0.50 7.37 N ATOM 5182 CA AMET K 406 13.685 5.798 25.578 0.50 5.87 C ATOM 5183 C AMET K 406 14.045 5.179 26.909 0.50 5.07 C ATOM 5184 O MET K... (14 Replies)
Discussion started by: hasanabdulla
14 Replies

6. Shell Programming and Scripting

Find number of characters in a column and replace

Hi all, I want to count total no. of characters in a column. and if no. of charaters are more than 3 then it must replace it by splitted string. ie, it must place a space after 3 characters. Ex: 21 435g asd3dd jklfjwe wer column number 3 has 4 alphanumeric character, so it must be splitted... (3 Replies)
Discussion started by: CAch
3 Replies

7. Shell Programming and Scripting

Counting the number of characters

Hi all, Can someone help me in getting the following o/p I/p:... (7 Replies)
Discussion started by: Sri3001
7 Replies

8. Shell Programming and Scripting

Count number of characters in particular column

Hi i have data like abchd 124 ldskc aattggcc each separated by tab space i want to count number of characters in 4th column and print it in new column with tabspace for every line can anyone help me how to do it. Thanks. (3 Replies)
Discussion started by: bhargavpbk88
3 Replies

9. UNIX for Dummies Questions & Answers

wc -c (number of characters)

for some reason word count always counts one extra character. for example, echo 11 | wc -c counts 3 characters instead of 2 anyone know how to get the exact number of characters? (1 Reply)
Discussion started by: metalwarrior
1 Replies

10. Shell Programming and Scripting

number of escape characters?

Hi, I am trying to execute the following command from a batch script, but no matter how many escape characters I put in it doesn't execute properly. It works fine from the command line with quotes around the -exec part. #!/bin/sh /usr/local/bin/sudo /usr/atria/bin/cleartool setview -exec... (0 Replies)
Discussion started by: Sebarry
0 Replies
Login or Register to Ask a Question