processing line in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting processing line in file
# 1  
Old 01-17-2006
Question processing line in file

Hi

I amtrying to read the lines from a file, these lines are absolute paths in the system. I want to check if these paths exists, if they doesn't I want to create that path and put a file in that location/path.

I had no trouble filtering these paths out using awk, grep, uniq etc but when it comes to write my own lite script that should process these lines I am clueless. I have been reading up awk but it seems a litle complicated, am I gooing in the right direction, what is the easiest way to solve this, what tools should I use?

Thanks in advance.

Cheers
fable00
# 2  
Old 01-17-2006
I just tried this and it seems I have a lead now. Smilie

cat /etc/hosts | while q=$(line); do echo $q; done


but feel free to give sugestions on how I should handle the logic with checking the if the file structure exists.


Cheers
fable00
# 3  
Old 01-17-2006
List of files with complete path

Code:
list.txt
/dir/a
/dir/b
/dir/c

Code:
while read file
do
if [ ! -d "$file" ] ; then
mkdir -p "$file"
touch "/$file/newfile"
fi ;
done < list.txt

That should be a starting point.

Not tested.
# 4  
Old 01-17-2006
Thanxs, it so great when you pick up and learn something new, it worked vino Smilie , thanxs again.
# 5  
Old 01-20-2006
need help in almost a similar case

Hi ,
I am trying to write a script which picks up each entry ( list of Filesystems in a file ) from a file and then checks whether that Filesystem was backed up or not ?

# Script to check for the backups of some particular Filesystems backup status
cat <one f ile >
while q=$(line)
do
echo $q > FS
mminfo -c gbo472b -t yesterday | grep $FS
if [ $? -eq 0 ]
then
echo "$FS was backed up "
else
echo "$FS was not backed up"
fi
done

but it is not working ..pls let me know the problem.
# 6  
Old 01-21-2006
This script looks like it was written for sh/ksh/bash. If so, the syntax seems to be incorrect.
Code:
#Script to check for the backups of some particular Filesystems backup status
######## cat <one f ile > # hashed this out. you don't need this
while read line; do
mminfo -c gbo472b -t yesterday | grep $line
if [ $? -eq 0 ]; then
   echo "$FS was backed up "
else
   echo "$FS was not backed up"
fi
done < /path/to/file/with/filesystem_list

I have no idea what mminfo does, just fixed some syntax errors in the script.
# 7  
Old 01-22-2006
Hi ,

Thanks for you reply.

But I wanted the script to pick each Filesystem status from the file and see whether it was backed up or not.

Looks like the way you are starting the script is wrong.
while read line; do
mminfo -c <clinet_name> -t yesterday | grep $line

My question is with out defining the variable line how can grep understand it.

Please reply back..

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

File Processing: Handling spaces in a line

Hi All, Iam trying to get a file processed and some lines have spaces...the below is not working Want to remove empty line Want to remove lines that start with # Avoid line with substring WHOA When trying to get the substring from the var also Iam having trouble file is like VAR=VALUE,... (13 Replies)
Discussion started by: baanprog
13 Replies

2. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

3. Shell Programming and Scripting

[awk] line by line processing the same file

Hey, not too good at this, so I only managed a clumsy and SLOW solution to my problem that needs a drastic speed up. Any ideas how I write the following in awk only? Code is supposed to do... For every line read column values $6, $7, $8 and do a calculation with the same column values of every... (6 Replies)
Discussion started by: origamisven
6 Replies

4. Shell Programming and Scripting

Line processing

If I have a line say like this 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 I want column 16 to be moved into column 4 and the rest same, like this 1 2 3 16 5 6 7 8 9 10 11 12 13 14 15 Using awk, I know that replacing $4 with $16 and typing all the column numbers will help. But, I have more... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

5. Shell Programming and Scripting

[string processing]Adding new line in file

I have a report file which somewhere has a lines starting with word ".sub" I have a new variable named $new. What i am trying to do is insert the content of $new just before the occurrence of ".sub" in the report file. How can I do that? (11 Replies)
Discussion started by: animesharma
11 Replies

6. Shell Programming and Scripting

reading a file inside awk and processing line by line

Hi Sorry to multipost. I am opening the new thread because the earlier threads head was misleading to my current doubt. and i am stuck. list=`cat /u/Test/programs`; psg "ServTest" | awk -v listawk=$list '{ cmd_name=($5 ~ /^/)? $9:$8 for(pgmname in listawk) ... (6 Replies)
Discussion started by: Anteus
6 Replies

7. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

8. Shell Programming and Scripting

Reading a file line by line and processing for each line

Hi, I am a beginner in shell scripting. I have written the following script, which is supposed to process the while loop for each line in the sid_home.txt file. But I'm getting the 'end of file' unexpected for the last line. The file sid_home.txt gets generated as expected, but the script... (6 Replies)
Discussion started by: sagarparadkar
6 Replies

9. Shell Programming and Scripting

File processing line by line

Hi, I am doing file processing line by line. while reading each line at a specified location I am searching for a particular character and then write that line to another file. Problem is while writing to another file it was supressing the spaces, which I don't want to do. Any help is... (1 Reply)
Discussion started by: suma
1 Replies
Login or Register to Ask a Question