UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 13th, 2005, 07:33 AM
rgord1 rgord1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: N.Ireland
Posts: 4 rgord1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 23 sec
Reputation Power: 0
Reading Specific line from a file??

Hello!

I need to process an unknown number of files each time to remove special characters and remove trailing blanks. My approach is this (I realise it's probably not the best code in the world but I like to keep things simple )

Code:
ls file* > list1
wc -l list1 > list2
COUNT1=1
COUNT2=`awk '{print substr($1,1,4)}' list2`
COUNT2=`expr $COUNT2 + 1`

while [ $COUNT1 -ne $COUNT2 ]
do


** read line from list1 using $COUNT1 to specify the next
 line at each pass. so, pass1 read line 1; 
pass 2 read line 2, etc. This is where I'm stuck!   How can I do it???

<process file>



COUNT1=`expr $COUNT1 + 1`
done




loop through each row from list1.lst one at a time and process each file using sed.

so

Problem is that I can't work out how to loop through 1 line at a time from list1.lst

Can you help me?

Thanks
Rich

Reply With Quote
  #2  
Old October 13th, 2005, 09:09 AM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,308 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 5 h 20 m 49 sec
Reputation Power: 48
This is how to read from a file. You can add a break statement iside an if block to end the loop early
Code:
#!/bin/ksh
let linecount=1
while read record 
do
     echo $record
     let linecount=$linecount+1
     if [ $linecount -eq $COUNT2 ]; then
         break;
     fi
done < list2

I really don't understand your question.

Reply With Quote
  #3  
Old October 14th, 2005, 02:03 AM
rgord1 rgord1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: N.Ireland
Posts: 4 rgord1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 23 sec
Reputation Power: 0
Jim

That was exactly that I was looking for!

Many thanks for your help and expertise,

Rich

Reply With Quote
  #4  
Old November 18th, 2005, 12:42 PM
iribach iribach is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 iribach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 31 m 47 sec
Reputation Power: 0
Not My Way

[QUOTE=rgord1]Hello!

I need to process an unknown number of files each time to remove special characters and remove trailing blanks. My approach is this (I realise it's probably not the best code in the world but I like to keep things simple )

Code:
ls file* > list1
wc -l list1 > list2
COUNT1=1
COUNT2=`awk '{print substr($1,1,4)}' list2`
COUNT2=`expr $COUNT2 + 1`

while [ $COUNT1 -ne $COUNT2 ]
do ......

COUNT1=`expr $COUNT1 + 1`
done




print line 200 (if present)

Code:
              sed-n '200p'


print lines 7-10

Code:
               sed -n '7,10p'


print line matching aaa at line begin

Code:
               sed -n '/^aaa/p'


print lines between aaa and zzz at line begin

Code:
                sed -n '/^aaa/,/^zzz/p'


and so on

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Reading Specific line from a file??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT