Removing columns with dashes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing columns with dashes
# 8  
Old 07-07-2010
Quote:
Originally Posted by Xterra
Thank you very much -I own you many at this stage Smilie
I tried your code
Code:
$ perl -nla -F"" -e 'if (!/^>/){$n++;for ($i=0;$i<=$#F;$i++){$a{$i}{$F[$i]}++}}END{for ($i=0;$i<=$#F;$i++){if ($a{$i}{"-"}/$n>0.5)\
> {print $i}}}' Input.txt | awk -vFS="" -vOFS="" 'NR==FNR{a[$0+1]++}{for (i=1;i<=NF;i++) if (i in a) $i=""}1' - Input.txt > Output.txt

and this is what I got
Code:
Backslash found where operator expected at -e line 1, near ")\"
(Missing operator before \?)
syntax error at -e line 1, near ")\"
syntax error at -e line 2, near ";}"
Execution of -e aborted due to compilation errors.
awk: cmd. line:1: fatal: cannot open file `Input.txt' for reading (No such file or directory)

Am I missing something?
Remove marked(red) backslash.
# 9  
Old 07-07-2010
bartus

It worked! I was just wondering why am I getting 2 different number at the very top of the file
Quote:
38
45
>GHL8OVD01BNNCA Freq 4
TAGATGTGCCCGTGGGTTTCCCGTCAACACCGGATAGTGCAGCATA
>GHL8OVD01CMQVT Freq 15
TTGATGTCGTGGGTTTCCCGTCAACACCGGCAAATAGTGCAGCATA
>GHL8OVD01CMQVT Freq 50
TTGATGTGCCAGTTTCCCGTCTAGCAGCACTACCAGGACTTCGCTA
>GHL8OVD01CMQVW Freq 700
TTGATGTGTCCCGTCGACACCGGCAAATAGCAGCAGCATACCAGAC
>GHL8OVD01A45V3 Freq 9
TTGATTCCCGTCGACACCGGCAAATAGCAGCAGCACTAAGGACCTC
>GHL8OVD01AV2U9 Freq 17
TTGATGTGCCAGCTTTCGCGTCGACACCGGCAAATAGTGCAGCGTA
I ran it in Cygwin, could that be the problem? I will try on my Linux (red hat) box.
# 10  
Old 07-07-2010
Right. My fault Smilie. Replace "1" at the end of AWK statement with "FNR!=NR", so it looks like:
Code:
$ perl -nla -F"" -e 'if (!/^>/){$n++;for ($i=0;$i<=$#F;$i++){$a{$i}{$F[$i]}++}}END{for ($i=0;$i<=$#F;$i++){if ($a{$i}{"-"}/$n>0.5)
> {print $i}}}' Input.txt | awk -vFS="" -vOFS="" 'NR==FNR{a[$0+1]++}{for (i=1;i<=NF;i++) if (i in a) $i=""}FNR!=NR' - Input.txt > Output.txt

# 11  
Old 07-07-2010
Syntax error

I got the following error
Code:
syntax error at -e line 2, near ")
>"
syntax error at -e line 2, near ";}"
Execution of -e aborted due to compilation errors.

# 12  
Old 07-07-2010
The ">" character was from your output, and it isn't part of the code:
Code:
perl -nla -F"" -e 'if (!/^>/){$n++;for ($i=0;$i<=$#F;$i++){$a{$i}{$F[$i]}++}}END{for ($i=0;$i<=$#F;$i++){if ($a{$i}{"-"}/$n>0.5)
 {print $i}}}' Input.txt | awk -vFS="" -vOFS="" 'NR==FNR{a[$0+1]++}{for (i=1;i<=NF;i++) if (i in a) $i=""}FNR!=NR' - Input.txt > Output.txt

# 13  
Old 07-07-2010
I got it!

It is working great on CygWin.
The Output file is empty when I run it on Red Hat though.
# 14  
Old 07-07-2010
I tested it on Oracle Enterprise Linux, which is based on Red Hat, so it should work..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Removing columns using awk

HI , I have a comma delimiter file, in which I want to remove 8th and 9th column. I tried removing those columns using the below code awk 'BEGIN { FS=","; OFS="," } {$8=$9="";gsub(",+",",",$0)}1' infile But the problem is 8th and 9th columns are user entered fields, theyvhave carriage... (1 Reply)
Discussion started by: mora
1 Replies

3. Shell Programming and Scripting

Removing columns using awk

HI , I want to remove 5th and 6th column from a .csv file using awk.is there any way of this apart from writing the each field as below awk -F, '{print $1,$2,$3,$7......$100}' OFS=, infile. Thx, Deepti (4 Replies)
Discussion started by: gaur.deepti
4 Replies

4. Shell Programming and Scripting

Removing columns from awk '{ print $0 }'

I have a one-line command, lsusb | awk '{ $1=""; $2=""; $3=""; $4=""; $5=""; $6=""; print $0 }' It works, and gives the results I expect, I was just wondering if I am missing some easier way to nullify the first 6 column variables? Something like, lsusb | awk '{ $(1-6)=""; print $0 }' But... (10 Replies)
Discussion started by: AlphaLexman
10 Replies

5. Shell Programming and Scripting

Removing blank columns from a file

Hi, I have a sample file as shown below -- id parent name dba -----------------------------------... (7 Replies)
Discussion started by: sumirmehta
7 Replies

6. Shell Programming and Scripting

Help removing lines with duplicated columns

Hi Guys... Please Could you help me with the following ? aaaa bbbb cccc sdsd aaaa bbbb cccc qwer as you can see, the 2 lines are matched in three fields... how can I delete this pupicate ? I mean to delete the second one if 3 fields were duplicated ? Thanks (14 Replies)
Discussion started by: yahyaaa
14 Replies

7. UNIX for Dummies Questions & Answers

Removing columns of a file using vi Editor

Hi Experts, I have a file which looks like in this way 1 2233|A.K Shukla |G.M |Sales |12/12/52|6000 2 9876|Jai Sharma |Director |Production |12/03/50|67000 3 5678|Sumit Chakarborty |D.G.M |Marketing |19/04/43|6000 4 2365|Barun... (2 Replies)
Discussion started by: DilipPanda
2 Replies

8. UNIX for Dummies Questions & Answers

Removing lines that are (same in content) based on columns

I have a file which looks like AA BB CC DD EE FF GG HH KK AA BB GG HH KK FF CC DD EE AA BB CC DD EE UU VV XX ZZ AA BB VV XX ZZ UU CC DD EE .... I want the script to give me only one line based on duplicate contents: AA BB CC DD EE FF GG HH KK AA BB CC DD EE UU VV XX ZZ (7 Replies)
Discussion started by: adsforall
7 Replies

9. Shell Programming and Scripting

removing spaces betweent columns

Hello Friends, Can any one help me with this issue: I would like to format a file: say if I have rows like: 4512 , SMITH , I-28984 ,, 4324 , 4343 42312 , SMITH , I-2EE8984 ,, 432E4E4 , 4343 I would like to have the output diaplayed like : 4512... (8 Replies)
Discussion started by: sbasetty
8 Replies

10. UNIX for Dummies Questions & Answers

help removing dashes from social security number

I have a file containing social security numbers with the format ###-##-####. I need to read each record in this file, reformat the SSN to the format #########, and write the record with the reformatted SSN to a new file. I am a UNIX newbie. I think I need to use either the sed or awk commands, but... (2 Replies)
Discussion started by: Marcia P
2 Replies
Login or Register to Ask a Question