Selecting lines with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Selecting lines with sed
# 1  
Old 05-20-2010
Selecting lines with sed

Hi all,
I have a file with special characters like this

file1
Code:
691775025 ýÄqJ8^Z^Y{ 2004-08-23E P 100.00
45585025 0527541139295037342008-07-25OEP 100.00
6983025 ýB<9D>x<^F^Xb 2004-11-16SPP 100.00

I need a sed command to print the lines which don't have special characters.ie., only line 2 should be printed from the file1

I was trying with the following command and it wasn't working.

Code:
sed -e '/^[-.0-9A-Za-z\s]$/p' file1

Can anybody help on this.

Moderator's Comments:
Mod Comment Please use code tags

Last edited by Scott; 05-20-2010 at 09:22 AM..
# 2  
Old 05-20-2010
try with:

Code:
egrep -v "\^" file1

# 3  
Old 05-20-2010
Quote:
Originally Posted by albertogarcia
try with:

Code:
egrep -v "\^" file1

Woow! Smilie How/why does that work? Can you explain, please?
# 4  
Old 05-20-2010
I'll try to explain it (in english).

the -v options shows lines that doesn't match the expresion.

"\^" is the expresion, I have considered the ^ character as the only "special" character in your expresions...

Maybe the solution doesn't run for other lines...
This User Gave Thanks to albertogarcia For This Post:
# 5  
Old 05-20-2010
All right, now I got it. Shame on me that I did not find out that myself. I was staring at that code and was wondering how can be that it filters out all the mentioned special chars Smilie
# 6  
Old 05-20-2010
Hi,
In my case, anything other than the following should be considered as special char.

Alphanumeric
-
.
whitespace(can be anywhere in the line)
# 7  
Old 05-20-2010
Code:
$ cat file
691775025 ýÄqJ8^Z^Y{ 2004-08-23E P 100.00
45585025 0527541139295037342008-07-25OEP 100.00
6983025 ýB<9D>x<^F^Xb 2004-11-16SPP 100.00
$ sed -n '/^[-.0-9A-Za-z ]*$/p' file
45585025 0527541139295037342008-07-25OEP 100.00
$ sed '/[^-.0-9A-Za-z ]/d' file
45585025 0527541139295037342008-07-25OEP 100.00

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Selecting lines having same values for first two columns

Hello to all. This is first post. Kindly excuse me if I do not adhere to any rules and regulations of this forum. I have a file containing some rows with three columns each per row(separeted by a space). There are certain rows for which first two columns have same value but the value in... (6 Replies)
Discussion started by: manojmalhotra13
6 Replies

2. Shell Programming and Scripting

sum of a column and selecting lines with value above threshold

Hi again, I need to further process the results of a previous manipulation. I have a file with three columns e.g. AAA5 0.00175 1.97996e-06 AAA5 0.01334 2.14159e-05 AAA5 0.01340 4.12155e-05 AAA5 0.01496 1.10312e-05 AAA5 0.51401 0.0175308 BB0 0.00204 2.8825e-07 BB0 0.01569 7.94746e-07 BB0... (6 Replies)
Discussion started by: f_o_555
6 Replies

3. Shell Programming and Scripting

selecting and deleting specific lines with condition

I have a set of data as below: The first field, $1 represent "|". The $3 (3rd field) and $6 (6th field) in my data file represent "number-molecule" which has arrangement as below: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... (9 Replies)
Discussion started by: vjramana
9 Replies

4. Shell Programming and Scripting

selecting lines using awk

I have a file which contains five hundred thousand lines (500,000). I want to select lines of every 1000 lines from that file using AWK. I can think something like this in bash as below: for lines in {0..500000..1000} do ........ ........ done But I want to use AWK. I do not know how to... (4 Replies)
Discussion started by: vjramana
4 Replies

5. Shell Programming and Scripting

Selecting specific 'id's from lines and columns using 'SED' or 'AWK'

Hello experts, I am new to this group and to 'SED' and 'AWK'. I have data (text file) with 5 columns (C_1-5) and 100s of lines (only 10 lines are shown below as an example). I have to find or select only the id numbers (C-1) of specific lines with '90' in the same line (of C_3) AND with '20' in... (6 Replies)
Discussion started by: kamskamu
6 Replies

6. Shell Programming and Scripting

Selecting lines of a file

Say I wanted to select the 5th line of a file without knowing the context of the file. Would I use grep and pipe it into wc or is there a more simple way of doing this? (3 Replies)
Discussion started by: puttster
3 Replies

7. Shell Programming and Scripting

Selecting a range of Lines

Hi All, Is there a way to get a range of lines from a file??? I want to search through a set of scripts and need to select the group of lines which do the FTP. Say, Line1 Line2 ftp SERVER user UNAME PASS send FILE_TO_BE_SENT close Line3 Line4 Line5 ftp SERVER1 user USER1 PASS1... (6 Replies)
Discussion started by: beinthemiddle
6 Replies

8. Shell Programming and Scripting

about selecting lines

Hello , i got text file like that' C:\Users\Public\Pictures\Sample Pictures\aa.jpg C:\Users\Public\Pictures\Sample Pictures\thumb.jpg C:\Users\Public\Pictures\vv\cc.jpg C:\Users\Public\Pictures\Sample Pictures\ee.jpg C:\Users\Public\aa\Sample Pictures\cvswsr.jpg... (1 Reply)
Discussion started by: davidkhan
1 Replies

9. Shell Programming and Scripting

Selecting Lines on text file

Hi All, I am creating a script that sends log data from text files to a Database and I will like to read sugestions, as I think that there might be better ways to achive this than with my shell script; maybe perl or I don't know, but I will like to read some sugestions. The log is from... (10 Replies)
Discussion started by: oconmx
10 Replies

10. Shell Programming and Scripting

selecting only few lines from many based on a common pattern

Hi, I have a file having some thousand records with the following sort of lines: Error: Failed to get order data Order: PO-BBBTGZE Error: No CLI Error: Failed to get order data Order: PO-SBDJUZA Order: PO-XBBIDEN Error: No CLI Error: Failed to get order data Order: PO-BBDJUTQ Order:... (2 Replies)
Discussion started by: damansingh
2 Replies
Login or Register to Ask a Question