Unix/Linux Go Back    

Post Here to Contact Site Administrators and Moderators Forum members, please contact us here (not via email or PM).
Bug reports and minor feature requests should be posted here.

How to read the nth character from the line.?

Post Here to Contact Site Administrators and Moderators


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by pavand
pavand's Unix or Linux Image
pavand pavand is offline
Registered User
 
Join Date: Dec 2017
Last Activity: 29 December 2017, 10:38 AM EST
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
How to read the nth character from the line.?

I have Index Line and I tried to get the 9th character from the file and to check the character is "|" or not.
Shell Scripting.


Sample Index file.



Code:
"91799489|K8E|188.004.A.917994892.1099R.c.01.pdf|2013|10/15/2014|002|B|C|C"
"917994898|K8E|188.004.A.917994892.1099R.c.01.pdf|2013|10/15/2014|002|B|C|C"

Attached Files
File Type: txt example.txt (131 Bytes, 25 views)
    #2  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by pavand
pavand's Unix or Linux Image
pavand pavand is offline
Registered User
 
Join Date: Dec 2017
Last Activity: 29 December 2017, 10:38 AM EST
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts


Code:
FIRSTLINE=`head -n 1 $indexFile

   while read -r line
   do
   id = cut -c 9 $FIRSTLINE
   echo $id 
done < "$indexFile"

    #3  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by pavand
Scott's Unix or Linux Image
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 20 January 2018, 3:43 PM EST
Posts: 9,014
Thanks: 389
Thanked 1,250 Times in 1,064 Posts
For the last time, please do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
The Following User Says Thank You to Scott For This Useful Post:
Neo (3 Weeks Ago)
    #4  
Old Unix and Linux 4 Weeks Ago   -   Original Discussion by pavand
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 20 January 2018, 3:42 PM EST
Location: Aachen, Germany
Posts: 11,961
Thanks: 353
Thanked 3,688 Times in 3,386 Posts
Welcome to the forum.

You've been told twice already to
- follow the rules.
- post in an adequate forum - certainly not "Post Here to Contact Site Administrators and Moderators".
- post homework ONLY in https://www.unix.com/homework-coursework-questions/ and fill in the form completely.
- use code tags

Sorry, this thread is closed again.
The Following User Says Thank You to RudiC For This Useful Post:
Neo (3 Weeks Ago)
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Read character by character in line in which space is also included pallvi_mahajan Shell Programming and Scripting 10 10-28-2014 02:21 PM
Search and recursively enter new line after Nth character Amit786 Shell Programming and Scripting 6 02-18-2014 03:02 PM
Read a file from the nth line on nw2unx123 Shell Programming and Scripting 2 03-20-2013 04:25 PM
Read file from nth line to specific character laalesh Shell Programming and Scripting 3 03-22-2012 09:58 AM
Read last word of nth line gc_sw Shell Programming and Scripting 3 11-02-2010 08:48 AM



All times are GMT -4. The time now is 04:43 PM.