Deleting lines if ith character is x


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Deleting lines if ith character is x
# 1  
Old 05-19-2011
Deleting lines if ith character is x

Hello,
I am trying to remove all lines of a data file if the 32nd character in the line is 0.

Is there a short, one-line way to do this with grep, awk, or sed?

Thanks!
# 2  
Old 05-19-2011
Code:
sed '/^.\{31\}0/d'

or:

Code:
grep -v '^.\{31\}0'

# 3  
Old 05-19-2011
Try:
Code:
perl -F"" -ane 'print if $F[31] ne "0"' file

# 4  
Old 05-19-2011
Thanks... those worked.
I do have another slight variation...
If there are tab delimited columns, and I wish do delete all lines where the first character in the 7th column is 0, what might be a quick way to do this.

Thanks again!
# 5  
Old 05-19-2011
Try:
Code:
perl -F"\t" -ane 'print if $F[6]=~/^[^0]/' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting rows starting with a character and word

Hi, I have multiple files of same format and I want to delete the lines starting with # and The from all of them I am using egrep -v '^(#|$)' for # but unable to do for both # and The Please guide Thanks (12 Replies)
Discussion started by: bioinfo
12 Replies

2. Shell Programming and Scripting

deleting lines in ex

Hello, im using ex to manipulate some text. Im trying to delete all the lines except those on which a certain regex can be found. the important part of the script: ex temp << 'HERE' g/regex/p HERE this command prints the lines I want to end up with, but it doesnt delete the others.... (2 Replies)
Discussion started by: drareeg
2 Replies

3. Shell Programming and Scripting

Deleting sequences based on character frequency

This is what I would like to accomplish, I have an input file (file A) that consist of thousands of sequence elements with the same number of characters (length), each headed by a free text header starting with the chevron ‘>' character followed by the ID (all different IDs with different lenghts)... (9 Replies)
Discussion started by: Xterra
9 Replies

4. UNIX for Dummies Questions & Answers

Deleting all instances of a certain character from a text file

In my command prompt I did: sed 's/\://' mytextfile > newtextfile But it only deleted the first instance of : in each line when some lines have multiple : appearing in each one. How can I delete all the : from the entire file? (1 Reply)
Discussion started by: guitarscn
1 Replies

5. Shell Programming and Scripting

Deleting particular lines.

hi all, i have got a scenario in which i need to delete all the lines that ends with file names. e.g. input can be cms/images/services_icons/callback.png cms/cms/images/services_icons/sync.php cms/cms/images/services_icons and output should be cms/cms/images/services_icons ... (13 Replies)
Discussion started by: kashifv
13 Replies

6. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

7. Shell Programming and Scripting

Deleting a character

Hi I have a file that looks like this: arg1 ert arg_7 ert arg_9 ert ban ert Basically what I want to do is delete the _# ending. So the output will look like this: arg1 ert arg ert arg ert ban ert thanks (5 Replies)
Discussion started by: kylle345
5 Replies

8. Shell Programming and Scripting

deleting a character

Hi I am having problems deleting a character Basically I want to recognize lines with > and then delete a character that is seperated by a space. Here is an example of how the file looks like. >chr86 86 Heres what I want it to look like: >chr86 thanks Phil (2 Replies)
Discussion started by: phil_heath
2 Replies

9. UNIX for Advanced & Expert Users

Deleting end of line $ character in file

Hi, I've got a file where in the middle of the record is a $ end of line character, visible only when I open the file in vi and do :set list. How to I get rid of the character in the middle and keep it at the end. The middle $ character always appears after SW, so that can be used to tag it.... (3 Replies)
Discussion started by: bwrynz1
3 Replies

10. UNIX for Dummies Questions & Answers

Problem deleting file with special character

I'm having problems deleting a file with a special character and I'm hoping that somebody here can help. The file "-osample1.c" will not remove from my directory. Here is an example of what happens. Any ideas would be appreciated. > ls *sample1* ls: illegal option -- . usage: ls... (2 Replies)
Discussion started by: hart1165
2 Replies
Login or Register to Ask a Question