Removing letters after a certain character within a range of columns


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Removing letters after a certain character within a range of columns
# 8  
Old 01-03-2017
Again sorry, Smilie

Not the Headers but the entire first 9 columns is there a way to make the code work but exempt the first 9 columns (i.e i want to keep the information after the : on the the the first 9 columns only) = Remove a selection of columns

Thanks
# 9  
Old 01-03-2017
Yes. Look at the code and how it loops across fields 10 until end-of-line. Now imagine what were needed to make it loop across fields 1 to 9...
This User Gave Thanks to RudiC For This Post:
# 10  
Old 01-03-2017
Code:
awk 'NR > 1 {for (i=1; i<=9; i++) sub (/:.*$/, _, $i)} 1' OFS="\t" file

Smilie

right?Smilie

I am trying to understand the logic behind this bit. I would be grateful if you can break it down ?
Code:
(/:.*$/, _, $i)

$ for the columns ? and the columns are specified earlier in I?
, _, substitute ? usually in sed i leave it empty for substitution when i want to remove it.
I always find awk is complicated, any good place to read more about it as I have more use for it for the same data to find in-common and unique values between range of columns (patients versus control)?

Thanks again
You are a life saver. I have been experimenting with this for 3 days :/

Last edited by daashti; 01-03-2017 at 01:22 PM..
# 11  
Old 01-03-2017
You got it, congrats! Here the sub logics (please note that $ means different things in regexes and in awk field designators):

Code:
(/:.*$/,        # regex greedily matching ":" then ANY char (multiple) until EOL designated by $
 _,             # _ is an undefined thus empty variable, equivalent to ""
 $i)            # in the loop, $i results in fields $1 .. $9

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking subset and removing extra letters

In each line of file, I wish to check if word1 is a non-connected subset of any of the other words in the line. If yes, keep only the words that ward1 is a subset of. Else, remove the whole line. Also, I want to remove the letters that word1 doesn't match with, except for "_+" Example file:... (2 Replies)
Discussion started by: Viernes
2 Replies

2. UNIX for Dummies Questions & Answers

Help with removing files with date range

Hi, I want to remove trace files in a particular directory for a specific date range. Currently i can remove based on time (e.g find /path/*.trm -mtime +1000 -exec rm {} \;). But i want to remove .trm files within a date range. E.g to remove .trm files between jan 1 2002 to April 15 2005. ... (3 Replies)
Discussion started by: dollypee
3 Replies

3. UNIX for Dummies Questions & Answers

Removing a range of files in a directory..

Hi all, Disclosure: I am very new to Unix, but eager to learn.. I've been tasked with transferring logs to a remote server. After I've verified these logs have transferred correctly I have to remove the source files. The naming scheme is: /directory/2012.05.01 /directory/2012.05.02 ..and... (1 Reply)
Discussion started by: JD3V
1 Replies

4. Shell Programming and Scripting

reducing values in columns with both numbers and letters

Hi, I columns with both number and letters however i need the number 4 trimmed off the lines that have 3 numbers in them so it just because the 2 preceding numbers only For example V25QG2-K18QG-V25CG2 L26HG-L17HA-L26CG I434QD1-L19HB2-I434CD1 I434QD1-A31QB-I434CD1 ... (7 Replies)
Discussion started by: olifu02
7 Replies

5. Shell Programming and Scripting

removing a range of characters in a filename

hi, I have quite a bunch of files with annoyingly long filenames. I wanted to cut the range of characters from 9-18 and just retain the first 8 characters and the .extension. any suggestion how to do it. thanks much. original filename: 20000105_20000105_20100503.nc.asc output filename:... (4 Replies)
Discussion started by: ida1215
4 Replies

6. UNIX for Dummies Questions & Answers

Removing columns from a text file that do not have any values in second and third columns

I have a text file that has three columns. But at the end of the text file, there are trailing lines that have missing second and third columns: 4 0.04972604 KLHL28 4 0.0497332 CSTB 4 0.04979822 AIF1 4 0.04983331 DECR2 4 0.04990344 KATNB1 4 4 4 4 How can I remove the trailing... (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

read into a range of character

i have this problem: i must hide a string with a character such as _ by command WORD=string; XXX=`echo $WORD | sed 's//_/g' but after, users must send in input a character and i must to replace the _ with the input character or better i can do this -$CHARS_INPUT i have think to use command... (3 Replies)
Discussion started by: tafazzi87
3 Replies

8. UNIX for Dummies Questions & Answers

Use of character range in awk

Hi all, I am having a bit of a hard time using awk. I must do something wrong, but I don't know what... Any help would be greatly appreciated! I read a file, as follows :... ATOM 21 C THR A 4 23.721 -26.194 1.909 1.00 32.07 C ATOM 22 O THR A 4 ... (2 Replies)
Discussion started by: hypsis
2 Replies

9. UNIX for Dummies Questions & Answers

Need help removing last character of every line if certain character

I need help removing the last character of every line if it is a certain character. For example I need to get rid of a % character if it is in the last position. Input: aaa% %bbb ccc d%dd% Output should be: aaa %bbb ccc d%dd I tried this but it gets rid of all of the % characters.... (5 Replies)
Discussion started by: raptor25
5 Replies

10. Shell Programming and Scripting

Removing Letters from Integer String

Hi all, I have a variable, on some machines it is '1024', which is fine, but on others it is '1024Mb' etc. I need this variable to simply be '1024', does anyone know how I could ensure this is always the case? Perhaps a command to remove any letters/characters that aren't integers if there is... (3 Replies)
Discussion started by: hodges
3 Replies
Login or Register to Ask a Question