Open txt and store line in a var


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Open txt and store line in a var
# 1  
Old 01-08-2009
Question Open txt and store line in a var

Hi

I realy need to find a way to do a script that does the following:

search a word in a txt file then store on a var the letters that are on the right

like
this is an exemple, I want to store from here ...abcdefg...

so I need a var that receive ...abcdefg...

Is that possible?
sorry if this is too basic but is my first thread
# 2  
Old 01-08-2009
Code:
value=""
# do this 
grep -q 'search text' inputfile && value="search text"

# or you can do this  pick one or the other
awk -v txt="search text" '{ if index($0, txt) > 0 ) { print txt; exit}' | read value

# then find out if it was in the file
if [ -z "$value" ] ; then
  echo "not found"
fi
echo "$value"

# 3  
Old 01-08-2009
VARIABLE=`cat filename | grep pattern | awk '{ print $2 }'`

Where what you want to store in the variable is in the second column of the line.
Padow
# 4  
Old 01-08-2009
Quote:
Originally Posted by jim mcnamara
Code:
grep -q 'search text' inputfile && value="search text"

I'm trying with this one. I guess that the first search text and the secund should be the same? so if I'm searching for 'lib' I should type

grep -q 'lib' /home/ruben/Desktop/rsyncbackup/2tuesday/diff.txt && value= "lib"

thanks a lot for your help
# 5  
Old 01-08-2009
Quote:
Originally Posted by Padow
VARIABLE=`cat filename | grep pattern | awk '{ print $2 }'`

Where what you want to store in the variable is in the second column of the line.
why exactly do you need a 'cat' and a 'grep'?
# 6  
Old 01-08-2009
you could read a file line by line, and store the entire line in a $VARIABLE, and then process the line further from there:

Code:
while read LINE ;do
 "start processing the $LINE variable"
done < file_to_read

# 7  
Old 01-08-2009
ok now I have this praticular case.
I do

cat -n /home/ruben/Desktop/rsyncbackup/2tuesday/diff.txt ¦ grep lib

and the output is:
1 change: lib32
2 metadata the same, data changed: lib32/jniwrap.lic
3 new: lib32/ruben file
4 new: lib32/ruben file 2
5 new: lib32/ruben file 2~

Is possible that I save in a array something like
array(0)=lib32/jniwrap.lic
array(1)=lib32/ruben file
array(2)=lib32/ruben file 2
array(3)=lib32/ruben file 2~

thanks for supporting me
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to store info from a txt file into a hash?

I'm trying to make a perl script using the "open" command to open and read a file, storing the information in said file into a hash structure. This is what is inside my file- Celena Standard F 01/24/94 Cancer Jeniffer Orlowski F 06/24/86 None Brent Koehler M 12/05/97 HIV Mao Schleich... (4 Replies)
Discussion started by: Eric1
4 Replies

2. Shell Programming and Scripting

Vim help.txt automatically open every time I open vi

Hi Friends, Every I try to open a vi window, vim help.txt automatically opens evertime. After doing ZZ or :q! also the same page opens automatically. How to stop this? Is it machine specific ? Other users who are opening the same servers and files are not facing this issue. Thanks... (3 Replies)
Discussion started by: sudiptabhaskar
3 Replies

3. UNIX for Beginners Questions & Answers

Vim help.txt automatically open every time I open vi

Hi Friends, Every I try to open a vi window vim help.txt automatically opens evertime. After doing ZZ or :q! also the same page opens automatically. How to stop this? Is it machine specific ? Other users who are opening the same servers and files are not facing this issue. Thanks... (1 Reply)
Discussion started by: sudiptabhaskar
1 Replies

4. UNIX for Dummies Questions & Answers

Split Every Line In Txt Into Separate Txt File, Named Same As The Line

Hi All Is there a way to export every line into new txt file where by the title of each txt output are same as the line ? I have this txt files containing names: Kandra Vanhooser Rhona Menefee Reynaldo Hutt Houston Rafferty Charmaine Lord Albertine Poucher Juana Maes Mitch Lobel... (2 Replies)
Discussion started by: Nexeu
2 Replies

5. Solaris

Configuring 'auditd' service to not store the audit logs in /var partition

Hello all, I've configured 'audit' service to send the audit logs to a remote log server (by using syslog plugin), which is working fine. However, there is a problem. audit service also tries to write same information (but in binary format) in /var/audit path. So, Is there anyway to stop... (2 Replies)
Discussion started by: Anti_Evil
2 Replies

6. Shell Programming and Scripting

Need to append the date | abcddate.txt to the first line of my txt file

I want to add/append the info in the following format to my.txt file. 20130702|abcd20130702.txt FN|SN|DOB I tried the below script but it throws me some exceptions. <#!/bin/sh dt = date '+%y%m%d'members; echo $dt+|+members+$dt; /usr/bin/awk -f BEGIN { FS="|"; OFS="|"; } { print... (6 Replies)
Discussion started by: harik1982
6 Replies

7. Shell Programming and Scripting

Store output of DB Cursor to a txt file

I am writing a cursor to select values from 3 tables. I want to store these values in a txt file which I will be sending via ftp. I am able to store the results of simple select queries to the txt file. but I am not sure how to store the values when using a cursor. I have given the sql query below.... (1 Reply)
Discussion started by: naveensraj
1 Replies

8. Shell Programming and Scripting

How to store the sql query output into txt file?

Hi I want ot save SQL query result in one txt file. for that i have written one code line sqlplus -s $dbstring @/usr/local/bin/sched/nightly_Cronjob/exec_123.sql >> /usr/local/bin/sched/nightly_Cronjob/result.txt but it is not working . database : Oracle so please advice me how can i... (7 Replies)
Discussion started by: Himanshu_soni
7 Replies

9. Solaris

unix txt files in M$: /var/adm/messages

hi I have a script that mails me when certain event are logged in /var/adm/messages. When the mail reaches me there are no line breaks (its just one really long line) so I tried piping the output of the script to a text file which I run `unix2dos` on then mail myself that, but that didn't work. ... (2 Replies)
Discussion started by: s1ckle
2 Replies

10. Shell Programming and Scripting

Store command in a Var problem

Hi! I strated to script since 1 month and I don't have much expirience but this thing here is strange I have a script where I want to store a svn command in a var to check it later so it's like this #!/bin/sh list=`ssh itadmin@192.168.1.200 "ls /home/svn"` # this stores the list of... (13 Replies)
Discussion started by: ruben.rodrigues
13 Replies
Login or Register to Ask a Question