LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-22-2014, 05:47 AM   #1
VijayB
LQ Newbie
 
Registered: Jun 2014
Posts: 21

Rep: Reputation: Disabled
Problem with reading multiple lines from multiple files


Hi All,

I am having a problem while reading multiple lines from multiple files. I have two files in the directory sat test. File names are test1.txt & test2.txt. Contents of the files are:

test1.txt:

[~/test]$ cat test1.txt
XYZ uniqueID ABC
DEF Price 800

test2.txt:

[~/test]$ cat test2.txt
xyz uniqueID 900
def Price abc


i want my code to grep multiple particular word from these 2 or multiple files of same type & process accordingly. But the code seems to not be working for multiple lines.
Code is:

Code:
#!/bin/bash
#Reading Multiple files

for file in ~/test/*; do
     k=1
    while read -r line; do
        Site="$(echo $file | sed 's/.txt$//'| cut --d="/" -f 5)"
        echo -e "\e[1;33mFile Checked = $Site \
        \e[0m\n"
        uniq="$(grep uniqueID | cut -f3 -d" ")"
        echo -e "Uniq IDs are :\n$uniq\n"
        AUG="$(grep Price  | cut -f3 -d" ")"
        echo -e "AUG is :\n$AUG\n"
        ((k++))
    done < "$file"
done
Output that i am getting is :

[~]$ ./test21.sh
Site Checked = test1

Uniq Hw IDs are :


AUG is :


Site Checked = test2

Uniq Hw IDs are :


AUG is :



Can somebody please suggest how to move forward with this.

Thanks in Advance!

BR\\Vijay
 
Old 11-22-2014, 07:33 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,842

Rep: Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756Reputation: 756
Your grep commands don't have any input. Get rid of the while loop an just pass $file to each grep.
 
Old 11-22-2014, 09:31 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
I am with the previous post. Your while loop is pointless as you do nothing with the read line anyway.
 
  


Reply

Tags
files


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Help: Searching multiple files and returning multiple lines matching querry thealmightyos Linux - General 14 09-17-2014 01:00 PM
[SOLVED] reading multiple lines into a string c++ brick2 Programming 2 05-16-2014 04:48 PM
[SOLVED] bash script reading specified lines from multiple files and concatenating into one TullyGirl Linux - Newbie 6 03-22-2013 11:29 PM
[SOLVED] [Perl] Reading multiple lines from a file Ziddy Programming 3 10-30-2012 08:27 AM
[SOLVED] CAT command | multiple lines to multiple lines udiubu Programming 11 10-28-2011 07:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:37 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration