How to take a full sentence and check the condition?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to take a full sentence and check the condition?
# 1  
Old 07-11-2011
How to take a full sentence and check the condition?

I have one input file and content of file is :
---------------------------------------------------
Input.txt
---------------------------------------------------
Code:
american express
Bahnbau GmbH
Bahnbau GmbH
CRH Europe
crh europe
Helgeland Ferdigbetong AS

---------------------------------------------------
i worte the script

Code:
for file in ` cat  input.txt `
do

echo $file

done


but instead of taking full line from the input file I am getting only one word instead of full line. Please help me how can I get the full line from the input file.

Last edited by Franklin52; 07-11-2011 at 06:43 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 07-11-2011
Try this

PHP Code:
for line in `cat file1.txt`;
do
echo 
$line
done 
# 3  
Old 07-11-2011
there is no difference between your and my code except ";", I tried but it is not working Smilie
# 4  
Old 07-11-2011
You can do it in below manner
Code:
while read line
do
  printf "%s\n" "${line}"
done <file1.txt

Cheers
Harish

Last edited by Franklin52; 07-11-2011 at 06:45 AM.. Reason: Please use code tags for code and data samples, thank you
# 5  
Old 07-11-2011
Actually I do not want to print the value. If value is present then create “Present.txt” otherwise “notpresent.txt” file.
Note: in input file I have more than 1000 record so only I want to read one by one.
# 6  
Old 07-11-2011
You can edit in below manner .
So if the value is present in file1.txt on that line it will put in file2.txt
if no value on that line it will put blank line
Same as file1.txt .. will read line by line from file1.txt and put into file2.txt
Code:
rm -f file2.txt 2>/dev/null
while read line
do
  printf "%s\n" "${line}" >> file2.txt
done <file1.txt


Cheers
Harish

Last edited by Franklin52; 07-11-2011 at 06:45 AM.. Reason: Please use code tags for code and data samples, thank you
# 7  
Old 07-11-2011
Look like some confusion happen here.
My input file is :
---------------------------------------------------
Input.txt
---------------------------------------------------
Code:
american express
Bahnbau GmbH
Bahnbau GmbH
CRH Europe
crh europe
Helgeland Ferdigbetong AS

---------------------------------------------------

I have to grep one by one input file details from the another file and store that information in “Present.txt”
If record is not present then store the input file search sentence in “not present.txt” file

Last edited by Franklin52; 07-11-2011 at 06:46 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check two condition in while loop

Hi, I Have to check two condition in while loop every 2 minutes. while loop is accompanied with number of times it will check.Please help in putting the two condition in while loop as appropriate. z= input value, A=1 while do 1.check the file output,if the file output is N then keep on... (2 Replies)
Discussion started by: netdbaind
2 Replies

2. Shell Programming and Scripting

If condition to check null variable

Guys, Please help me on the below sample.cfg var=NULL sample.sh #!/bin/sh . /sample.cfg if ;then 1 st command here else 2 nd command here fi (3 Replies)
Discussion started by: AraR87
3 Replies

3. Red Hat

Need to check full utilization of my pc RAM - any commands ???

hi guys, I wanted to utilize my PC's full RAM memory to check its performance, for that how can i perform this full RAM utilization with the help of a process or a command in rhel 6. for example, in windows, while checking the harddisk for error (chkdsk - command ) could takes full RAM... (7 Replies)
Discussion started by: redhatlbug
7 Replies

4. UNIX for Dummies Questions & Answers

Condition check using awk

Hi, I have a file in the following format "SYLVESTER,WILLARD G"|"S00633600"|"221052958A"|"H2256"|"015"|""|"00000042BASJ"|"665303"|"N"|"20100211"|"380.4"|""|""|""|"5400"|"20110218"|""|"20110218"|"FEESC"|"D"|"F"|"P" "PURINGTON-KELLEY,C"|"S00808783"|"029424717A"|"H2256"|"024"|"MEMBER JOINED... (3 Replies)
Discussion started by: nua7
3 Replies

5. Shell Programming and Scripting

Regex to identify a full-stop as a sentence delimiter

Hello, Splitting a sentence using the full-stop/question-mark/exclamation is a common device. Whereas the question-mark / exclamation do not pose too much of a problem; the full-stop as a sentence delimiter raises certain issues because of its varied use: just to name a few. Standard parsers... (9 Replies)
Discussion started by: gimley
9 Replies

6. Shell Programming and Scripting

Check if Queue empty or full in perl

Hi, I got problem with queue code how to determined empty and full and problem with while loop Here is my pseudo code : Input page Access Input Pgae Frame For i =3 to pageframe count by 1 construct queue of size i set pageFaultCount to 0 while morepages do page = NextPage... (1 Reply)
Discussion started by: guidely
1 Replies

7. UNIX for Dummies Questions & Answers

Script to ask for a sentence and then count number of spaces in the sentence

Hi People, I need some Help to write a unix script that asks for a sentence to be typed out then with the sentence. Counts the number of spaces within the sentence and then echo's out "The Number Of Spaces In The Sentence is 4" as a example Thanks Danielle (12 Replies)
Discussion started by: charlie101208
12 Replies

8. Shell Programming and Scripting

WHILE LOOP CONDITION CHECK

Hello I want to compare values of two variables as CHECK condition in a while loop. eg: var1=0 var2=10 while do echo " $var1 " var1=`expr $var1 + 1` done However this is giving error.How to do it in a proper manner? Thanks. (3 Replies)
Discussion started by: dashing201
3 Replies

9. HP-UX

fsck! How to run Full File System Check

Dear all I am new for HP-UX. I have HP rp2470 running HP-UX 10.x When i run fsck in a root, the output is as below: #:root> fsck fsck: /dev/vg00/rlvol1: mounted file system continue (y/n)? y ** /dev/vg00/rlvol1 ** Last Mounted on /stand ** Phase 1 - Check Blocks and Sizes ** Phase... (3 Replies)
Discussion started by: hungevntelecom
3 Replies
Login or Register to Ask a Question