Ignore commented lines and lines which as "/"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ignore commented lines and lines which as "/"
# 1  
Old 04-11-2009
Question Ignore commented lines and lines which as "/"

Hi all,

I have a file like file1.txt
contents in file1.txt
==============
#paths
/opt/new/sample1.sh
/var/opt/new1/sample2.sh
/
#

here ,
i need to omit the lines which is commented and the line which the root directory"/" alone is specified

i will assign the file to a variable ex. PATH
so when i echo $PATH
I should get the output as
/opt/new/sample1.sh /var/opt/new1/sample2.sh

please provide me as solution.

Regards,
NG
# 2  
Old 04-11-2009
Hi,
you could try this:

PATH=$(awk '/opt/,/var/ {print}' file1.txt )

Bye

Last edited by Neo; 04-11-2009 at 07:40 AM.. Reason: change "should" to "could"
# 3  
Old 04-11-2009
It is better if you don't use PATH as your variableSmilie
I forgot to tell you this
it's better using another name because PATH is used as an environment variable
Bye
# 4  
Old 04-11-2009
egrep, mmmm

mypath=$(egrep -v '^(#|\/$)' file1.txt)

ksh -
omits any lines beginning with # or lines containing ONLY /
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining especific lines in "2n" lines file

Hi to everybody. I have a "2n" lines file. I would like to create a new file with only "n" lines, each line in the new file formed by the proper odd line of the old file joined with the following even line (separated by a space) of the old file. I'd prefer using sed or bash. -example-... (5 Replies)
Discussion started by: felino
5 Replies

2. UNIX for Dummies Questions & Answers

Grep : Filter/Move All The Lines Containing Not More Than One "X" Character Into A Text File

Hi All It's me again with another huge txt files. :confused: What I have: - I have 33 huge txt files in a folder. - I have thousands of line in this txt file which contain many the letter "x" in them. - Some of them have more than one "x" character in the line. What I want to achieve:... (8 Replies)
Discussion started by: Nexeu
8 Replies

3. Shell Programming and Scripting

Grep all lines with the string "TNS-" but skip those with "TNS-12514"

Platform: Oracle Linux 6.3 From a log file, I want to grep all lines with the pattern "TNS-" but I want to skip those with the pattern "TNS-12514" . How can I do this ? (3 Replies)
Discussion started by: John K
3 Replies

4. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

5. Shell Programming and Scripting

Cat Command on File not printing "Blank" Lines?

Hello All, I have a bash script and in it at some point I call an Expect Script that does some stuff and saves its output in a ".txt" file. Example "/path/to/my/file/Expect_Output.txt" file: notice the 2nd line is empty in the file... Data for Host-1 (192.168.1.110) Checking the... (2 Replies)
Discussion started by: mrm5102
2 Replies

6. Shell Programming and Scripting

awk? extract quoted "" strings from multiple lines.

I am trying to extract multiple strings from snmp-mib files like below. ----- $ cat IF-MIB.mib <snip> linkDown NOTIFICATION-TYPE OBJECTS { ifIndex, ifAdminStatus, ifOperStatus } STATUS current DESCRIPTION "A linkDown trap signifies that the SNMP entity, acting in... (5 Replies)
Discussion started by: genzo
5 Replies

7. Shell Programming and Scripting

Perl- Finding average "frequency" of occurrence of duplicate lines

Hello, I am working with a perl script that tries to find the average "frequency" in which lines are duplicated. So far I've only managed to find the way to count how many times the lines are repeated, the code is as follows: perl -ae' my $filename= $ENV{'i'}; open (FILE, "$filename") or... (10 Replies)
Discussion started by: acsg
10 Replies

8. Shell Programming and Scripting

How to print range of lines using sed when pattern has special character "["

Hi, My input has much more lines, but few of them are below pin(IDF) { direction : input; drc_pinsigtype : signal; pin(SELDIV6) { direction : input; drc_pinsigtype : ... (3 Replies)
Discussion started by: nehashine
3 Replies

9. Shell Programming and Scripting

Need to parse file "x" lines at a time ... awk array?

I have files that store multiple data points for the same device "vertically" and include multiple devices. It repeats a consistant pattern of lines where for each line: Column 1 is a common number for the entire file and all devices in that file Column 2 is a unique device number Column 3 is... (7 Replies)
Discussion started by: STN
7 Replies

10. UNIX for Dummies Questions & Answers

How to count lines - ignoring blank lines and commented lines

What is the command to count lines in a files, but ignore blank lines and commented lines? I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end. Here is an example of what I would like my... (6 Replies)
Discussion started by: kthatch
6 Replies
Login or Register to Ask a Question