Skip item by using substring


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Skip item by using substring
# 1  
Old 12-16-2005
Question Skip item by using substring

I have a file contents like this....

item1
item2
#item3
item4
#item5
item6
....

I have a KSH script to read this file into an array.
I have a for loop which will read each item...
I want to be able to skip those item start with # sign as first character in a if condiction inside the for loop.

How can I use substr, or parse or whatever way in ksh to detect the first character is a # sign.

Thanks in advance.
# 2  
Old 12-16-2005
Try this

grep -v "^#" file.dat | \
while read line
do
echo "Storing into array"
done
# 3  
Old 12-16-2005
Code:
#!/bin/ksh

file='rw.txt'

while read line
do
   (( $(expr "${line}" : '^#') )) && continue;
   echo "line->[${line}]"
done < "${file}"

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Confused on how to script item

I am working on a script that will parse the /proc/meminfo file and return values. I have been able to pull the MemTotal and MemFree from that file but have stumbled on the next thing I want to do - calculate memory used via subtracting MemFree from MemTotal. Would I do something like - ... (5 Replies)
Discussion started by: flyboynm
5 Replies

2. Shell Programming and Scripting

perl - get uniq item from an array?

practicing perl now and hope to get uniq item from an array: my current work: #!/usr/local/bin/perl my @source = ("aaa", "aaa", "bbb", "ccc", "ddd"); my $index=0; my @uniq; foreach (@source) { chomp; # push first item to @uniq if ($index == 0) { push @uniq, $_; ... (2 Replies)
Discussion started by: tiger2000
2 Replies

3. Shell Programming and Scripting

Print new item in file with symbol

Dear all, I have encountered some problem here. I prompt the user for input and store it into a data file, eg. key in name and marks so the data file will look like this andrew 80 ben 75 and the next input is carine 90. So the problem here is i want to print... (2 Replies)
Discussion started by: branred
2 Replies

4. Solaris

Add item to crontab

hi, how can I add a new value to crontab file using a script not using the command " crontab -e " . ex: echo " 10 10 * * * " >> /var/spoll/cron/crontabs/<username> how can I do that in a correct way?? thanks, (3 Replies)
Discussion started by: Ahmed waheed
3 Replies

5. UNIX for Dummies Questions & Answers

replace item..

Hello, I have the following basic script which is remove the fielld. How can I replace another value in the field? Thx!! for file in `cat $listn.txt` do get_file -q $file grep -v '<customer-id>13000</customer-id>' $file > $file.grep done echo All processed file done!! input file:... (2 Replies)
Discussion started by: happyv
2 Replies

6. Shell Programming and Scripting

find an available item in array

Dear all, I'm have a sorted array like this: 177 220 1001 2000 2001 2003 2005 notice that 2002 and 2004 are NOT in array. Then user input a number INPUT, our script should return OUTPUT value like this: if INPUT is not in array => OUTPUT=INPUT if INPUT is in array => OUTPUT is the... (4 Replies)
Discussion started by: fongthai
4 Replies

7. Shell Programming and Scripting

change some record item

Hi all, I have a file with over 10,000 line, but I would like to update/add some code number (such as 062 below) into the line with <phone number> below: 11111<name> john matin <name> 12345<phone number> 123456 <phone number> 34556 <address> 1234 lucky road <address> 11111<name> john... (7 Replies)
Discussion started by: happyv
7 Replies

8. Shell Programming and Scripting

Removing an item from the dock

Hello! I am able to add an item to the dock with this command: defaults write com.apple.dock persistent-apps -array-add... (1 Reply)
Discussion started by: emperorfabulous
1 Replies
Login or Register to Ask a Question