String starting with blank space


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String starting with blank space
# 1  
Old 03-18-2011
String starting with blank space

[quotes]
Dear Masters,

Need your help for this small query.
I am trying to get all the strings that starts with a blank space as output.
Limitation is , it should be done only through AWK.

Input will be:
Code:
aa
 _1bbb
 c-ccc
ddd
 eeeee
 ff

Output should be:
Code:
_1bbb
 c-ccc
 eeee
 ff


Last edited by Franklin52; 03-21-2011 at 05:02 AM.. Reason: Please use code tags
# 2  
Old 03-18-2011
Quote:
Originally Posted by patric2326
Dear Masters,

Need your help for this small query.
I am trying to get all the strings that starts with a blank space as output.
Limitation is , it should be done only through AWK.

Input will be:

aa
_1bbb
c-ccc
ddd
eeeee
ff

Output should be:
_1bbb
c-ccc
eeee
ff
bad quoting ...
# 3  
Old 03-18-2011
Code:
awk '/^ /' filename

# 4  
Old 03-18-2011
print all lines starting with blank :
Code:
awk '/^[[:blank:]]/' infile

print all lines except those starting with blank:

Code:
awk '!/^[[:blank:]]/' infile


Last edited by ctsgnb; 03-18-2011 at 05:38 PM..
# 5  
Old 03-21-2011
Thanks to ALL for your reply.
For reply:1 -> I'm getting the output as:
Code:
awk '/^ /' infile
 _1bbb  yes
 c-ccc  yes
 eeeee  yes
 ff  yes

But when I tried something as below, inorder to do conditional manipulation based on the value of $1, I didn't get any output.
Code:
>awk '{ if($1 ~ /^  /) {print $0}}' infile

For reply:2 -> I'm not getting the desired output which I think may be because [:blank:] searches for tab space.

Code:
>awk '/^[[:blank:]]/' infile ---> no output
>awk '!/^[[:blank:]]/' infile
aa  no
 _1bbb  yes
 c-ccc  yes
ddd  no
 eeeee  yes
 ff  yes

FYI, my infile have below contents:
Code:
>cat infile
aa  no
 _1bbb  yes
 c-ccc  yes
ddd  no
 eeeee  yes
 ff  yes

Regards,

Last edited by Franklin52; 03-21-2011 at 05:03 AM.. Reason: Please use code tags
# 6  
Old 03-21-2011
This works correctly for me
Code:
$ awk '/^[[:blank:]]/' file
 _1bbb  yes
 c-ccc  yes
 eeeee  yes
 ff  yes

Perhaps you need to use nawk or gawk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a string and count following lines starting with another string

I have a large dataset with following structure; C 0001 Carbon D SAR001 methane D SAR002 ethane D SAR003 propane D SAR004 butane D SAR005 pentane C 0002 Hydrogen C 0003 Nitrogen C 0004 Oxygen D SAR011 ozone D SAR012 super oxide C 0005 Sulphur D SAR013... (3 Replies)
Discussion started by: Syeda Sumayya
3 Replies

2. Shell Programming and Scripting

Removing blank space using VI

Hi, How to remove blank spaces using vi (I am using AIX)? #cat siva.txt AAA BBB CCC DDD EEE FFF Need to remove space between 2 columns. Regards, Siva (7 Replies)
Discussion started by: ksgnathan
7 Replies

3. Shell Programming and Scripting

Not delete space blank

Hi everyone, i need to "grep" a file with a string with space blanks, like this: grep "XXXX XX" file.txt The problem, i need put the "XXXX XX" in a string variable. When the script executes the grep, do: gresp XXXX XX file.txt How can i solve this problem? The... (5 Replies)
Discussion started by: Xedrox
5 Replies

4. UNIX for Dummies Questions & Answers

blank space

hi everyone, i have a problem in unix script , i need to remove line that has blank , not blank line . example: mahm,,jdggkhsd,ghskj,,fshjkl can anyone help? (4 Replies)
Discussion started by: Reham.Donia
4 Replies

5. Shell Programming and Scripting

substitute the starting dollar sign in command with blank

Hi,, Let example cmd: $$config/all Here I want to replace or subsitute blank space and also with any other character in place of "$" sign...and also want to replace backslash (/) with forward (\)......in expect script please could any one help on this.....thank you (2 Replies)
Discussion started by: swethakast
2 Replies

6. Shell Programming and Scripting

Cut last blank space

Hello, I am using this to get only directories : ls -l | grep '^d'and here is the result : drwx------ 13 so_nic sonic 13 Nov 4 13:03 GLARY drwx------ 3 so_nic sonic 3 May 6 2010 PSY2R drwx------ 15 so_nic sonic 15 Oct 14 08:47 PSYR1 But I only need to keep this... (7 Replies)
Discussion started by: Aswex
7 Replies

7. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

8. UNIX for Dummies Questions & Answers

Matching exact string with blank space using grep

hi! i'm trying to get grep to do an exact match for the following pattern but..it's not quite working. I'm not too sure where did I get it wrong. any input is appreciated. echo "$VAR" | grep -q '^test:]name' if ; then printf "test name is not found \n" fi on... (4 Replies)
Discussion started by: jazzaddict
4 Replies

9. Shell Programming and Scripting

Replace a blank space with string "\\ "

Hi, I have a requirement to replace a every blank space with char "\\ ". Like string "God Love" to "God\\ Love" and "God Love" as "God\\ \\ Love". and only in the sed. We have already a script but it is replaceing all continuous blank space with one "\\ ". which is as DIR=`sudo echo... (7 Replies)
Discussion started by: Akshay4u
7 Replies

10. Shell Programming and Scripting

append blank space

Hi, I would like to add blank space for fixed length(50) if length of string <30. Scenario: File Size AAA.CSV 123 BB.CSV 134 Expected: File Size AAA.CSV 123 BB.CSV 134 I want append blank space until 30 character. Thanks and Regards, HAA (1 Reply)
Discussion started by: HAA
1 Replies
Login or Register to Ask a Question