read a part of information from txt and put into the script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read a part of information from txt and put into the script
# 1  
Old 10-23-2006
read a part of information from txt and put into the script

Hi,

I have a name.txt which is stored:

APPLE
ORANGE
RED
BLUE
GREEN

and my script is:
$name=`cat name.txt
for file_number in `ls 1 /appl/CH_DATA/archive/CACHE/CDBACKUP$name*.archived

however, my script cannot read name.txt and put into my scrip line, I would like the output is to list all

CDBACKUPAPPLE*.archived
CDBACKUPORANGE*.archived
# 2  
Old 10-23-2006
Same reply that read a part of filename from the list in the script
You can try something like this :

Code:
while read name
do
   ls -l CDBACKUPFILE${name}*.archived
done <list.txt


Jean-Pierre.
# 3  
Old 10-23-2006
Quote:
Originally Posted by happyv
Hi,

I have a name.txt which is stored:

APPLE
ORANGE
RED
BLUE
GREEN

and my script is:
$name=`cat name.txt
for file_number in `ls 1 /appl/CH_DATA/archive/CACHE/CDBACKUP$name*.archived

however, my script cannot read name.txt and put into my scrip line, I would like the output is to list all

CDBACKUPAPPLE*.archived
CDBACKUPORANGE*.archived

plz give the complete script, n plz copy paste it. closing back-quotes are missing in the script. what do u want the for loop to do?

ls 1 /appl/CH_DATA/archive/CACHE/CDBACKUP$name*.archived

what is '1' doing in the above line?
n if u want the asterisk (*) to be in the output, escape it with a backslash, \*...else the shell will evaluate it as a metacharacter
# 4  
Old 10-23-2006
#!/bin/sh
start=1
while read name
do
ls -1 /appl/CH_DATA/archive/00000/CACHE/${name}*.archived | grep -v _9_4_bfmh.archived | grep -v _orig.archived >>output.txt
done <list.txt
for file_number in `cat list10.txt | grep -v _9_4_bfmh.archived | grep -v _orig.archived | sort | cut -c 43,44,45,46,47`
do
if [ $start -eq 1 ] ; then
# this is the first pass of the loop, so we've got nothing to compare
start=0
previous=$file_number
else
# this is not the first pass of the loop
previous=`expr $previous + 1`
#echo "comparing $file_number and $previous ... "
if [ $file_number = $previous ] ; then
echo "ok"
else
seqno=`expr $file_number - 1`
echo "CDBACKUP${name}$seqno are not in sequence "
fi
fi
previous=$file_number
done

#The above is my full script, the list.txt is like:
JOHN1
MARRY
PETER
CATT1


The full filename in CACHE directory is like:
CDBACKUPJOHN100001.archived
CDBACKUPJOHN100002.archived
CDBACKUPJOHN100004.archived
CDBACKUPMARRY00381.archived
CDBACKUPMARRY00382.archived
CDBACKUPMARRY00383.archived
CDBACKUPPETER01101.archived
CDBACKUPPETER01102.archived
CDBACKUPPETER01105.archived

I need to check the jump seq and show the full name which file is missing like:

CDBACKUPJOHN00003 is missing
CDBACKUPMARRY is no missing
CDBACKUPPETER01103 is missing
CDBACKUPPETER01104 is missing
# 5  
Old 10-23-2006
please help!!!! many Thanks!
# 6  
Old 10-23-2006
Code:
cat list10.txt | grep -v _9_4_bfmh.archived | grep -v _orig.archived | sort |
awk ' BEGIN { flag = "y" }
{ if(str != substr($0,1,13)) 
  {
	if ( flag == "n" ) print str " is no missing"
  	str = substr($0,1,13);
	seq = substr($0,14,5);
	flag = "n"
  }
  else
  {	
	seq1 = substr($0,14,5)
	seq = int(seq) + 1;
	if( seq != int(seq1) )
	{
	flag="y"
	  while( seq++ != int(seq1) )
	  {
		printf("%s%05d%s\n", substr($0,1,13), seq, " is missing")				
	  }
	}
  }
}'

# 7  
Old 10-23-2006
Another try

Code:
ipfile=./ipfile  #inputfile where the names are stored
tmpfile=./tmp.txt #tempfiles used
tmpfile1=./tmp_used.txt  #temp file
while read fname  #the outer loop 
do
if [[ -f $tmpfile ]]; then
rm -f $tmpfile
fi
if [[ -f $tmpfile1 ]]; then
rm -f $tmpfile1
fi

ls ${fname}*|while read name  #getting the existing sequence seperately
do
echo ${name##${fname}} >>$tmpfile1
done

sort -n $tmpfile1 >$tmpfile  #Sort the sequences for a particular file pattern
rm -f $tmpfile1

awk -v fnam=$fname 'NR==1{num=$1;num++;} NR!=1{while($1 >  num) {print fnam num, "is missing"; num++; found=1;} num++} END{if(found==0){print fnam, "has nothing missing" } }' $tmpfile 

done <$ipfile
rm -f $tmpfile

You may have to format the filenames a little bit to get the listing you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies

2. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

3. Shell Programming and Scripting

Needed shell script to read txt file and do some modification

Hi ...programmers... I need a shell script to perform some specific task.. my txt file looks like this netcdf new { dimensions: XAX1_11 = 11 ; variables: double XAX1_11(XAX1_11) ; XAX1_11:point_spacing = "even" ; XAX1_11:axis = "X" ; float DEPTH(XAX1_11) ;... (19 Replies)
Discussion started by: Akshay Hegde
19 Replies

4. Shell Programming and Scripting

Please Help! Need to put the lines of a txt to one line

Hi all, I'm quite newbie in shell scripting but I found a problem what I cant solve. I have a .txt file which looks like this: /22/ /23/ /24/ and so on and I'd need to make it look like this: /22/|/23/|/24/|...and so on. these numbers are growing and has lines like this /2a/ as well.... (15 Replies)
Discussion started by: gergo235
15 Replies

5. Shell Programming and Scripting

how to read strings from a txt and put them into a spreadsheet?

i have hundreds of thousands of txt files as below, RADARSAT 1 SCENE DESCRIPTION SCENE_ID c0005098 MDA ORDER NUMBER GEOGRAPHICAL AREA CIS ScanSar Canada SCENE START TIME APR 02 1997 23:05:10.222 SCENE STOP TIME APR 02 1997 23:02:49.695... (5 Replies)
Discussion started by: sunnydanniel
5 Replies

6. Shell Programming and Scripting

How to read userid and password information from txt file

Hi Experts, I am writing a shell script (for displaying disk space details) which is logging to 15 different servers using following command. ssh userid@servername It is prompting me for password for all 15 servers when I manually run it. However , soon I would like to schedule this script... (4 Replies)
Discussion started by: ajaypatil_am
4 Replies

7. Programming

extracting information from lines, put them into arrays

hi I need a little help writing this small perl script. I'm trying to extract the values from each line in a file and find the average for example cat school Highschool 100, 123, 135 Middleschool 41, 67, 54 Elementary 76, 315, 384 ./average.pl highschool: 119.3 middleschool: 54... (2 Replies)
Discussion started by: gengar
2 Replies

8. Shell Programming and Scripting

Extract zip code information from address, put into new column

Hi, suppose I have a colon delimeterd file with address field like this blue:john's hospital new haven CT 92881-2322 yellow:La times copr red road los angeles CA90381 1302 red:las vegas hotel sand drive Las vegas NV,21221 How do I create a new field that contain the zip code information... (3 Replies)
Discussion started by: grossgermany
3 Replies

9. Shell Programming and Scripting

sed to read x.txt and grep from y.txt

How would I write a command(s) to read from a file (list) that looks like this: 29847374384 and grep from a second file (list) that looks like this: 29847374384, jkdfkjdf,3833,ddd:confused: (1 Reply)
Discussion started by: smellylizzard
1 Replies

10. Shell Programming and Scripting

read a part of filename from the list in the script

how can i read a part of filename from the list in the script? all file in directory...will start with "CDBACKUPFILE" then the name is stored in list.txt such as JOHN,MARRY,PETER. After this, is seq number. CDBACKUPFILEJOHN00001 CDBACKUPFILEMARRY00004 CDBACKUPFILEPETER00003 I will use:... (3 Replies)
Discussion started by: happyv
3 Replies
Login or Register to Ask a Question