Print lines where there's no indent on the first field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print lines where there's no indent on the first field
# 1  
Old 01-15-2009
Print lines where there's no indent on the first field

Hi All,

I need a code to print those lines where there's NO indents on the 1st field
Example shown below.
I tried to use the below codes but i am not able to see the expected result.
Can any expert give any advise ?

My Code
Code:
cat filename| awk '$1 ~ /^[0-9]+$/ {print $0}'

Input
Code:
1199  ccc  zzz
1200  bbb  nnn
      1200  mmm  kkk
      1200  ppp  yyy
      1200  uuu  ttt
1201  vvv  ppp
1202  ccc  qqq


Output
Code:
1199  ccc  zzz
1200  bbb  nnn
1201  vvv  ppp
1202  ccc  qqq

# 2  
Old 01-15-2009
Code:
grep -v '^[[:blank:]]' filename

# 3  
Old 01-15-2009
Hi cfajohnson,

I tried your code but it does not get the expected result.
# 4  
Old 01-15-2009
Try this:

Code:
grep '^   *'  filename

So it was a NOT??? Didn't noticed that. Post below is correct

Last edited by angheloko; 01-15-2009 at 05:50 AM.. Reason: Wrong solution...Sorry, post below got it :)
# 5  
Old 01-15-2009
Code:
sed '/^ /d' file

# 6  
Old 01-15-2009
Which character do you use to indent? space or tab..you need to use that char after the ^ in the reg exp.

Code:
grep  -v '^ ' filename

Quote:
Originally Posted by Raynon
Hi All,

I need a code to print those lines where there's NO indents on the 1st field
Example shown below.
I tried to use the below codes but i am not able to see the expected result.
Can any expert give any advise ?

# 7  
Old 01-15-2009
Quote:
Originally Posted by Raynon
Hi cfajohnson,

I tried your code but it does not get the expected result.

So what did you get? In what way was it not what you wanted?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk - If field value of consecutive records are the identical print portion of lines

I have some data that looks like this: PXD= ZW< 1,6 QR> QRJ== 1,2(5) QR> QRJ== 4,1(2) QR> QRJ== 4,2 QRB= QRB 4,2 QWM QWM 6,2 R<C ZW< 11,2 R<H= R<J= 6,1 R>H XZJ= 1,2(2) R>H XZJ= 2,6(2) R>H XZJ= 4,1(2) R>H XZJ= 6,2 RDP RDP 1,2 What I would like to do is if fields $1 and $2 are... (5 Replies)
Discussion started by: jvoot
5 Replies

2. UNIX for Beginners Questions & Answers

Print lines based upon unique values in Nth field

For some reason I am having difficulty performing what should be a fairly easy task. I would like to print lines of a file that have a unique value in the first field. For example, I have a large data-set with the following excerpt: PS003,001 MZMWR/ L-DWD// * PS003,001... (4 Replies)
Discussion started by: jvoot
4 Replies

3. Shell Programming and Scripting

awk to print lines based on text in field and value in two additional fields

In the awk below I am trying to print the entire line, along with the header row, if $2 is SNV or MNV or INDEL. If that condition is met or is true, and $3 is less than or equal to 0.05, then in $7 the sub pattern :GMAF= is found and the value after the = sign is checked. If that value is less than... (0 Replies)
Discussion started by: cmccabe
0 Replies

4. Shell Programming and Scripting

Print field after pattern in all lines

data: hello--hello1--hello2--#growncars#vello--hello3--hello4--jello#growncars#dello--gello--gelloA--gelloB#growncars# I want to be able to print all the values that are found between the patterns "#growncars#" and the next "#growncars#" on the same line. so the output should be: ... (8 Replies)
Discussion started by: SkySmart
8 Replies

5. Shell Programming and Scripting

Print ALL lines except if field is 999

Hi All!!! :-) I need a command that will print each line of a text file UNLESS the 3rd field of that line is equal to the number 999. (space seperated fields) Solaris10/BASH SHELL: INPUT.TXT aaa bbb 111 222 ccc ddd 333 444 eee fff 999 555 ggg hhh 666 777 aaa bbb 999 222 ccc ddd 333... (7 Replies)
Discussion started by: ajp7701
7 Replies

6. Shell Programming and Scripting

Awk: print lines with one of multiple pattern in the same field (column)

Hi all, I am new to using awk and am quickly discovering what a powerful pattern-recognition tool it is. However, I have what seems like a fairly basic task that I just can't figure out how to perform in one line. I want awk to find and print all the lines in which one of multiple patterns (e.g.... (8 Replies)
Discussion started by: elgo4
8 Replies

7. Shell Programming and Scripting

Using awk, print all the lines where field 8 is equal to x

Using awk, print all the lines where field 8 is equal to x I really did try, but this awk thing is really hard to figure out. file1.txt"Georgia","Atlanta","2011-11-02","x","","","","" "California","Los Angeles","2011-11-03","x","","","",""... (2 Replies)
Discussion started by: charles33
2 Replies

8. Shell Programming and Scripting

Compare Tab Separated Field with AWK to all and print lines of unique fields.

Hi. I have a tab separated file that has a couple nearly identical lines. When doing: sort file | uniq > file.new It passes through the nearly identical lines because, well, they still are unique. a) I want to look only at field x for uniqueness and if the content in field x is the... (1 Reply)
Discussion started by: rocket_dog
1 Replies

9. Shell Programming and Scripting

How to indent the file lines using vi?

Every now and then I have to indent the lines in my script to 4 space characters. I generally do it line by line. Is there an automated command in vi using which I can indent some set of lines to desired number of space characters in one go. (2 Replies)
Discussion started by: paragkalra
2 Replies

10. Shell Programming and Scripting

print running field average for a set of lines

Hi everyone, I have a program that generates logs that contains sections like this: IMAGE INPUT 81 0 0.995 2449470 0 1726 368 1 0.0635 0.3291 82 0 1.001 2448013 0 1666 365 1 0.0649 0.3235 83 0 1.009 2444822 0 1697 371 1 ... (3 Replies)
Discussion started by: euval
3 Replies
Login or Register to Ask a Question