grep any number of spaces


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep any number of spaces
# 1  
Old 09-02-2010
grep any number of spaces

which one of the following is the correct expression to ignore line with multiple spaces after any string

Code:
cat file | grep -v "xyz *$"

or
Code:
cat file | grep -v "xyz[ ]*$"


do i need "[ ]*" to specify the sapce or " *" will do?

Last edited by Scott; 09-02-2010 at 04:46 AM.. Reason: Please use code tags
# 2  
Old 09-02-2010
Hi.

Neither of them?

Can the statement:
Quote:
ignore line with multiple spaces after any string
Be simplified to:
Quote:
ignore line with consecutive spaces
?

If so:
Code:
grep -v "  " file # two spaces, no need for cat

" *" means zero or more spaces. In extended regular expressions " +" means one or more spaces. Neither of these seems to fit your requirement.
# 3  
Old 09-02-2010
Quote:
Originally Posted by manishma71
which one of the following is the correct expression to ignore line with multiple spaces after any string

Code:
cat file | grep -v "xyz *$"

or
Code:
cat file | grep -v "xyz[ ]*$"


do i need "[ ]*" to specify the sapce or " *" will do?
Try:
Code:
grep -v "[ *$]" file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for an undetermined number of spaces

I would like to find an undetermined number of spaces and shorten them to one space. I am running Debian in mksh. Script running in #!/bin/sh. Sorry to not include all code. The program is too big and involves an online file... too much hassle to solve a simple issue. Ex., I start with... (11 Replies)
Discussion started by: bedtime
11 Replies

2. Shell Programming and Scripting

Printing a specific number of spaces

when given a file name, im looking for the most efficient way to turn each letter of the file name into spaces. for instance, the way im thinking of going about this is this: MYFILE=check_disks.sh CHANUM=$(echo ${MYFILE} | awk '{ print length }') printf '%s\n' $CHANUM as you can see... (4 Replies)
Discussion started by: SkySmart
4 Replies

3. Shell Programming and Scripting

Print a specific number of spaces

i'm looking for a command that allows me to print a specific number of spaces which i will provide. something as simple as: spaces=4 printf " " * $spaces i'm looking for somethign that'll allow me to print a specific amount of spaces on a line. can awk be used for this? (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

Grep lines for number greater than given number

Hello, I am newbie to bash scripting. Could someone help me with the following. I have log file with output as shown below **************************LOG************************* 11/20/2013 9:11:23.64 Pinging xx.xx.xx.xx with 32 bytes of data: 11/20/2013 9:11:23.64 Reply from xx.xx.xx.xx:... (4 Replies)
Discussion started by: meena_2013
4 Replies

5. Shell Programming and Scripting

sed to replace the matching pattern with equal number of spaces

Hi I have written a shell script which used sed code below sed -i 's/'"$Pattern"'/ /g' $FileName I want to count the length of Pattern and replace it with equal number of spaces in the FileName. I have used $(#pattern) to get the length but could not understand how to replace... (8 Replies)
Discussion started by: rakeshkumar
8 Replies

6. Shell Programming and Scripting

determine the number of spaces

Here is a weird question :) i am trying to create a script written in bash that will create configuration files for nagios. As some of you aware is has to be written in the below format: define service{ option1 value1 option2 value2... (6 Replies)
Discussion started by: ppolianidis
6 Replies

7. Shell Programming and Scripting

Replacing line number w/spaces in DSDT compiler log

Hi, all, I'm from the 8-bit micro days (Z-80, 6809, 6502, etc.) and used to program in assembly and machine code. But, that was 25 years ago and life happened. Now, I'm scripting for the hackintosh community and love every bit of it. I'm parsing a DSDT compiler log for error/warning/remarks... (0 Replies)
Discussion started by: digital_dreamer
0 Replies

8. Shell Programming and Scripting

construct a string with X number of spaces

I'd like to create a variable with the value of X number of space( no Perl please), printf seems to work, but , in following example,10 spaces becomes 1 space when assinged to a variable, Why? other solutions are welcome. $printf "=%10s=\n" = = $var=$(printf "=%10s=\n") echo... (4 Replies)
Discussion started by: honglus
4 Replies

9. Shell Programming and Scripting

grep spaces

Hi all, I'm writing a program that scans a file for a name and/or number the user enters ie: $ sh phone.sh "Sally Turner" or $ sh phone.sh Bob 12345678 I've got it mostly working except when I use "" to try make a full name one argument ie "sally turner" it scans for a turner file in the... (3 Replies)
Discussion started by: javajynx
3 Replies

10. Shell Programming and Scripting

Split File of Number with spaces

How do i split a variable of numbers with spaces... for example echo "100 100 100 100" > temp.txt as the values can always change in temp.txt, i think it will be feasible to split the numbers in accordance to column. How is it possible to make it into $a $b $c $d? (3 Replies)
Discussion started by: dplate07
3 Replies
Login or Register to Ask a Question