Exclude lines which have blanks at certain positions


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Exclude lines which have blanks at certain positions
# 1  
Old 10-18-2008
CPU & Memory Exclude lines which have blanks at certain positions

Hi All,

I am getting a input file which doesnt have a field seperator. The file is being sorted on certain positions say from 0.55 to 0.59. If there are any blanks from 0.55 to 0.59 they will be listed as first set of records. I am not sure abt the number of records which will have blanks at those positions (0.55 - 0.59), but have to exclude all those lines which have blanks from 0.55 to 0.59.

eg : sort -y -T /temp/usespace +0.55 -0.59 <input filename> >> <output filename>

Is there any one line command to this ??? If not then how to go abt this ???

Please let me know regarding the same.
# 2  
Old 10-18-2008
Please post sample input and example of the desired output.
# 3  
Old 10-19-2008
Code:
$ cat data
123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234     0

$ perl -ne 'print unless $_ =~ /^.{54} {5}/' data
123456789012345678901234567890123456789012345678901234567890

Pipe the output of this to your sort routine, or sort directly in perl.
MrC
# 4  
Old 10-19-2008
you can use this simple awk command

Code:
awk '{if(substr($0,55,5)!="     "){print}}' filename

then you can pipe it to your sort command
# 5  
Old 10-19-2008
Here goes the input file :
Name of the file is test
000000000XXXXXXX XXXXXXXX NOTIXABCDHH450
000000000XXXXXXX XXXXXXXX NOTIXABCDHH450
000000000YYYYYY YYYYY NOTIXPQRSPULSAR
000000000YYYYYY YYYYY NOTIXPQRSPULSAR
000000000ZZZZZ ZZZZZZZ NOTIXABCDHH450
000000000ZZZZZ ZZZZZZZ NOTIXABCDHH450
000000000PPPPPPP PPPPPPP PAGI5 0000
000000000PPPPPPP PPPPPPP PAGI5 0000
000000000ZALKIM FERER NOTIXABCDZM371
000000000ZALKIM FERER NOTIXABCDZM371


I run this command

cat test | sort -y -t /tmp/usespace +0.55 -0.59

Here is the output of it
000000000PPPPPPP PPPPPPP PAGI5 0000
000000000PPPPPPP PPPPPPP PAGI5 0000
000000000XXXXXXX XXXXXXXX NOTIXABCDHH450
000000000XXXXXXX XXXXXXXX NOTIXABCDHH450
000000000ZZZZZ ZZZZZZZ NOTIXABCDHH450
000000000ZZZZZ ZZZZZZZ NOTIXABCDHH450
000000000ZALKIM FERER NOTIXABCDZM371
000000000ZALKIM FERER NOTIXABCDZM371
000000000YYYYYY YYYYY NOTIXPQRSPULSAR
000000000YYYYYY YYYYY NOTIXPQRSPULSAR

Now the first 2 lines have 4 spaces between PAGI5 and 0000.
Similary there may be so many lines which have blanks from position 55 to 59. I want to exclude all those lines on a fly and write others to another file.

I want to exclude all lines that have spaces at those positions meaning starting at 55 and ending at 59

Let me know regarding the same.
# 6  
Old 10-19-2008
Replace cat with the command either vidyadhar85 or I gave.

FYI: Place your code or output inside code blocks [ code ] ... [ / code ] (without any spaces inside the brackets).
MrC
# 7  
Old 10-19-2008
Code:
egrep -v '^.{55}     '

(assuming your columns start at 1; use {54} for 0-based)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing certain positions in lines with spaces

Hello, I have a file with hundreds of lines. Now I need to replace positions 750-766 in each line (whatever there is there) with spaces... how can I do that? Which command to use? The result will be all the lines in the file will have spaces in positions 750-766. Thanks! (3 Replies)
Discussion started by: netrom
3 Replies

2. Shell Programming and Scripting

Exclude multiple lines using grep

Hi, I'm working on a shell script that reports service status on a database server. There are some services that are in disabled status that the script should ignore and only check the services that are in Enabled status. I output the service configuration to a file and use that information to... (5 Replies)
Discussion started by: senthil3d
5 Replies

3. Shell Programming and Scripting

Filter lines based on values at specific positions

hi. I have a Fixed Length text file as input where the character positions 4-5(two character positions starting from 4th position) indicates the LOB indicator. The file structure is something like below: 10126Apple DrinkOmaha 10231Milkshake New Jersey 103 Billabong Illinois ... (6 Replies)
Discussion started by: kumarjt
6 Replies

4. Shell Programming and Scripting

File lines starts with # not processed or exclude that lines from processing

I have a file like below #Fields section bald 1234 2345 456 222 abcs dddd dddd ssss mmmm mmm mmm i need do not process a files stating with # I was written code below while read -r line do if then echo ${line} >> elif then ... (3 Replies)
Discussion started by: Chenchireddy
3 Replies

5. Shell Programming and Scripting

File lines starts with # not processed or exclude that lines

I have requirement in my every files starting lines have # needs to be not processing or exclude the that lines. I have written a code like below, but now working as expected getting ERROR" line 60: 1 #!/bin/sh 2 echo ======= LogManageri start ========== 3 4 #This directory is... (1 Reply)
Discussion started by: Chenchireddy
1 Replies

6. Shell Programming and Scripting

awk script replace positions if certain positions equal prescribed value

I am attempting to replace positions 44-46 with YYY if positions 48-50 = XXX. awk -F "" '{if (substr($0,48,3)=="XXX") $44="YYY"}1' OFS="" $filename > $tempfile But this is not working, 44-46 is still spaces in my tempfile instead of YYY. Any suggestions would be greatly appreciated. (9 Replies)
Discussion started by: halplessProblem
9 Replies

7. Shell Programming and Scripting

regular expression grepping lines with VARIOUS number of blanks

Hi, I need a regular expression grepping all lines starting with '*' followed by a VARIOUS number of blanks and then followed by the string 'Runjob=1'. I tried that code, but it doesn't work: grep -i '*'+'Runjob=1' INPUT_FILE >>OUTPUT_FILE Can someone help me? Thanks (8 Replies)
Discussion started by: ABE2202
8 Replies

8. Shell Programming and Scripting

exclude lines in a loop

I use while do - done loop in my shell script. It is working as per my expectations. But I do not want to process all the lines. I am finding it difficult to exclude certain lines. 1) I do not want to process blank lines as well as lines those start with a space " " 2) I do not want to... (2 Replies)
Discussion started by: shantanuo
2 Replies

9. Shell Programming and Scripting

awk modifying entries on 2 lines at 2 positions

Hi this script adds text in the correct place on one line only, in a script. awk 'BEGIN{ printf "Enter residue and chain information: " getline var < "-" split(var,a) } /-s rec:/{$7=a; } {print}' FLXDOCK but I need the same info added at position 7 on line 34 and... (1 Reply)
Discussion started by: gav2251
1 Replies
Login or Register to Ask a Question