The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read file until certain line position finalight Shell Programming and Scripting 5 05-21-2008 12:16 AM
Read value from particular position in file. krishnarao Shell Programming and Scripting 2 05-15-2008 03:49 AM
read space filled file and replace text at specific position COD Shell Programming and Scripting 6 04-21-2008 02:40 AM
How to read the configuration file from shell script nishanth hampal Shell Programming and Scripting 7 02-26-2008 11:42 PM
Korn Shell Script - Read File & Search On Values run_unx_novice Shell Programming and Scripting 2 06-15-2005 04:20 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-06-2006
lok lok is offline
Registered User
 

Join Date: Jul 2006
Posts: 3
Exclamation read or search the item in a file sequentially by position using unix shell script?

Is it we can read or search the item in a file sequentially by the position using unix shell script..??

The position i means is: for example..
inside the xxx file, it contain with:
----------------------------------------------------------------------
1200120136420 1210324120 12145123
1200120136420 1210324120 22178210
----------------------------------------------------------------------
position:
12345678901234567890123 4

Then i wanna grep or search for value in position 24 = 0.
like that.. position is count space by space or character or alphanumeric length..

Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-07-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
What is the significance of
Code:
position:
12345678901234567890123 4
Try this.

Code:
[/tmp]$ cat in
1200120136420 1210324120 12145123
1200120136420 1210324120 22178210
[/tmp]$ cat try.ksh
#! /bin/ksh

typeset -L24 left
typeset -R1 right

while read line 
do
        left=$line
        right=$left
        echo $right
done < in
[/tmp]$ ./try.ksh
0
0
[/tmp]$
Reply With Quote
  #3 (permalink)  
Old 07-07-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,510
Code:
awk 'substr($0,24,1)=="0"  '  filename
Reply With Quote
  #4 (permalink)  
Old 07-11-2006
lok lok is offline
Registered User
 

Join Date: Jul 2006
Posts: 3
Quote:
Originally Posted by jim mcnamara
Code:
awk 'substr($0,24,1)=="0"  '  filename
How if i wan to replace the 0 with any other variable??

I had try this :
#
item=10023
awk 'substr($0,24,1)=="$item" ' filename
#

but it cannot work. the system will take the $item as a string directly.
Reply With Quote
  #5 (permalink)  
Old 07-12-2006
lok lok is offline
Registered User
 

Join Date: Jul 2006
Posts: 3
Thanks vino.
One more question need ur help.

I write two while loop.
Can i know how to exit the second loop and go back to first loop. What is the exit status code??
i've tried 0 1 2 3 4, but it can't works.
Reply With Quote
  #6 (permalink)  
Old 07-12-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
Quote:
Originally Posted by lok
Thanks vino.
One more question need ur help.

I write two while loop.
Can i know how to exit the second loop and go back to first loop. What is the exit status code??
i've tried 0 1 2 3 4, but it can't works.
Are you talking about nested while loops ?

Code:
while read file1line
do
  while read file2line
  do
    echo "$file1line $file2line"
    break 1
  done < file2
done < file1
Reply With Quote
  #7 (permalink)  
Old 07-12-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,510
Code:
#!/bin/ksh
myvariable="A"
awk -v var=$myvariable 'substr($0,24,1)==var  '  filename
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:45 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0