The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 03:16 AM
Read value from particular position in file. krishnarao Shell Programming and Scripting 2 05-15-2008 06:49 AM
read space filled file and replace text at specific position COD Shell Programming and Scripting 6 04-21-2008 05:40 AM
How to read the configuration file from shell script nishanth hampal Shell Programming and Scripting 7 02-27-2008 03:42 AM
Korn Shell Script - Read File & Search On Values run_unx_novice Shell Programming and Scripting 2 06-15-2005 07:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread 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..

  #2 (permalink)  
Old 07-07-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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]$
  #3 (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.
  #4 (permalink)  
Old 07-12-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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
  #5 (permalink)  
Old 07-12-2006
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,759
Code:
#!/bin/ksh
myvariable="A"
awk -v var=$myvariable 'substr($0,24,1)==var  '  filename
  #6 (permalink)  
Old 07-07-2006
jim mcnamara jim mcnamara is online now Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,759
Code:
awk 'substr($0,24,1)=="0"  '  filename
  #7 (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.
Closed Thread

Bookmarks

Tags
grep or

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0