Script doesn't append to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script doesn't append to file
# 1  
Old 03-19-2012
Network Script doesn't append to file

Hello,

I have a script and it doesn't append text to a file:

Code:
#!/bin/bash
#set -x
if [ "$1" == "" ]
  echo "usage of full text search in files:"
  echo "fts filename searchword"
else
  cd /
  find . -type f -name $1 | tee /tmp/allfiles.out | nl | tail -n 1 | awk '{FS=" "; printf $1"\n";}' > /tmp/filecnt.out
  cnt=$(cat /tmp/filecnt.out)
  cntpart=$(expr $cnt / 20)
  #echo $cnt":"$cntpart
  fd=0
  rm /tmp/af.out 2>/dev/null
  rm /tmp/fl.out 2>/dev/null
  rm /tmp/fg.out 2>/dev/null
  touch /tmp/af.out
  echo -n "start to search in files .."
  while read l
  do
    less $l 2> /dev/null > /tmp/fl.out
    grep $2 /tmp/fl.out > /tmp/fg.out
    fs=$(ls /tmp/fg.out -l | awk '{FS=" "; printf $5;}')
    #echo "filesize: "$fs
    if [ "$fs" -gt 0 ]; then
      #echo "found another file..."
      echo "file: "$l >> af.out
      less /tmp/fg.out >> af.out
    fi
    fd=$(expr $fd + 1)
    if [ "$fd" -eq $cntpart ]; then
      echo -n ".."
      fd=0
    fi
  done < /tmp/allfiles.out
  more /tmp/af.out
fi

the file 'af.out' isn't filled with content although there is something found.
can please somebody help with this problem?

Last edited by daWonderer; 03-19-2012 at 08:19 AM..
# 2  
Old 03-19-2012
Does this line fs=$(ls /tmp/fg.out -l | awk ...) meant to be as fs=$(ls -l /tmp/fg.out | awk ..) ..?
# 3  
Old 03-19-2012
Quote:
Originally Posted by michaelrozar17
Does this line fs=$(ls /tmp/fg.out -l | awk ...) meant to be as fs=$(ls -l /tmp/fg.out | awk ..) ..?
ehm.. no - I usually use this syntax and it works Smilie

the lines don't work are:
Code:
echo "file: "$l >> af.out
less /tmp/fg.out >> af.out

EDIT: OK, as I'm in root directory and look for changes in /tmp/af.out I can not see any changes or appended text. Smilie

Last edited by daWonderer; 03-19-2012 at 08:53 AM..
# 4  
Old 03-19-2012
Quote:
ehm.. no - I usually use this syntax and it works
What Operating System and version do you have.
Can you show this syntax working? It should be an error because "ls" will try to find a file called "-l".
# 5  
Old 03-19-2012
1st parameter is the file to show in format in 2nd parameter given..

Code:
// Linux version 2.6.32-33-server (Ubuntu 4.4.3-4ubuntu5) //


Last edited by methyl; 03-19-2012 at 11:57 AM..
# 6  
Old 03-19-2012
What's happend to the "/tmp/" before af.out ?
This User Gave Thanks to vbe For This Post:
# 7  
Old 03-19-2012
thanks, already found out I forgot to set the path in front of the filename..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh remote command doesn't work from script file

I have 10 application servers in a distributed architecture generating their own application logs. Each server has application utility to continuously tail the log. for example following command follows tails and follows new logfiles as they are generated server1$ logutility logtype When I run... (8 Replies)
Discussion started by: indianya
8 Replies

2. Shell Programming and Scripting

How to print and append output of nawk script in commandline and as well into a file?

Hi All, I am working on nawk script, has the small function which prints the output on the screen.Am trying to print/append the same output in a file. Basically nawk script should print the output on the console/screen and as well it should write/append the same result to a file. script :... (3 Replies)
Discussion started by: Optimus81
3 Replies

3. Shell Programming and Scripting

i writing a unix script but i want to out put a file and append on it.

i have an existing script that is used to send an e-mail containing the alrams that appear on the server. But i need to create a daily log file containing all the alarms that was send that day. i tired to add at the and of the script a command, echo command but for some reason the file was... (1 Reply)
Discussion started by: ashraf_victory
1 Replies

4. UNIX for Dummies Questions & Answers

Script to append contents of one file to another

Hi, I want to write a script that will write a couple of lines into a file, including the output of another file... Can anyone help? Scenario Day 1 File 1 Contents --> Japan File 2 contents (to be wriiten by the script) --> Name: Sameer Country: Japan Day 1 File 1... (0 Replies)
Discussion started by: carlos_anubis
0 Replies

5. Shell Programming and Scripting

Script to append text from one file into another

Hello all. I was wondering if it possible to write a bash script that would do the following: I perform molecular modelling calculations and the output files are all text files with various different extensions. For example, I submit the input file "job_name.inp" and when it is done or the... (18 Replies)
Discussion started by: marcozd
18 Replies

6. Shell Programming and Scripting

Unix Script file to Append Characters before rows in file.

Hi Experts, I am working on HP-UX. I am new to shell scripting. I would like to have a shell script which will prefix: 1. "H|" before first row of my file and, 2. "T" for all other rows of the file. For Example - File before running the script 20100430|4123451810|218.50|TC 20100430 ... (4 Replies)
Discussion started by: phani333
4 Replies

7. Shell Programming and Scripting

ftp put in shell script -- whole file doesn't upload

Hi I'm having some trouble with a bash shell script that I'm writing. In the script, I'm trying to upload a file to a backup repository using ftp, but the whole file doesn't get uploaded. This is the file's properties at the start (I've highlighted the file size in red): -rw-r--r-- 1 root... (2 Replies)
Discussion started by: Viola
2 Replies

8. Shell Programming and Scripting

How to append value at first line of CSV file using shell script?

I have an issue where I need to append a value at the last of the csv, I have created a shell script and it is appending the columns at the last but it is appending at all lines, and my requirement is specific to just append at the 1st line. Have a look and suggest, (7 Replies)
Discussion started by: anujrichhariya
7 Replies

9. Shell Programming and Scripting

Sending/append result from CSH script to xls file

Hi, 1st post... Done a quick search for this so apologies if I've missed it. Basically I want to output and and append several values generated by a csh script direct to an xls openoffice file, rather than send to txt file and then physically copy and paste to xls file. Already I send... (4 Replies)
Discussion started by: scottyjock
4 Replies

10. Shell Programming and Scripting

Need a script to Append date to generated .txt file

Hi, Can anyone plz share their experience with - Building shell script to append the file with date in following format- Filename_MMDDYYYY.txt Thanks in advance (2 Replies)
Discussion started by: prince_of_focus
2 Replies
Login or Register to Ask a Question