LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-22-2011, 10:12 AM   #16
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612

Nice pure-shell solution Grail! Even avoids any dependence on array feature of the shell.
Here's even more portable examples:
Code:
#!/bin/bash

while read -r LINE ; do

    # avoid blank lines
    case $LINE in '') continue;; esac
    
    # no bash>2.x ?, instead of array use set
    set - ${LINE}
    
    # either of these two work with bash or sh-as-bash
    #echo ${4//[\{\}:,\"]/}
    #echo ${4//\"/}
    
    # these two together works with bash, sh-as-bash and dash
    #OUT=`echo ${4%\"*}`
    #echo ${OUT#*\"}
    
    # this works with bash, sh-as-bash, dash and jsh
    eval echo ${4}
    
done < example-data-file
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i read two files word by word at a time using any loop by shell script? vaibhavs17 Programming 16 03-19-2010 03:48 AM
word by word comparison in two files using loop in shell script vaibhavs17 Programming 2 03-05-2010 07:41 AM
URGENT----shell script to change word in file raghupal Programming 14 10-21-2008 12:49 AM
search a file for a word - bash script paul_mat Linux - Software 12 04-16-2006 01:59 AM
How to read ans parse MS word file using a Linux Shell script. Alek Linux - General 2 11-10-2003 02:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration