Sponsored Content
Top Forums Shell Programming and Scripting Script for writing to files with sed Post 69228 by Trufla on Wednesday 13th of April 2005 10:30:10 AM
Old 04-13-2005
Script for writing to files with sed

I have a problem with syntax methinks, when it comes to sed.

This is my script for a user to type sed commands:-
Code:
yes=y

function writefunction
{
$tool $command $newfilename $filename
}

echo
echo
echo "1. Type the name of the tool you are using i.e sed."
         read tool
echo
echo "2. Type any criteria you are searching for. And remember:-"
echo "   You can do this in conjunction with command options like -n or p to affect the search and view output."
echo "   You can also search characters or whole names by enclosing them in / /, but do not forget to tell the tool what to"
echo "   do with those characters - Use the 'w' write command!"
         read command
echo
echo "3. Type a name for a new file where the output is to be redirected."
         read newfilename
echo
echo "4. Type the name of the original file you searched i.e Myfile"
         read filename
#------------------------------------------------------------------------
#Call the function 'writefunction'
echo
echo "Your results are:-"
echo "--------------------------------------"
             writefunction
echo "--------------------------------------"
echo
echo "Do you want to see the contents of the file you just created?"
echo "Type 'y' for Yes. Press any key for No."
      read answer
    if [ "$answer" = "$yes" ]
     then
      clear
 cat $newfilename
    else
echo "New file $newfilename will not be displayed at this time."
    fi

echo "Where do you want to go?"
echo
echo "------------------"
echo "1. Previous Menu"
echo "2. Main Menu"
echo "3. QUIT"
echo
echo "Please select (1,2 or 3)................."
read menunumber
case $menunumber in
     1)./page2;;
     2)./page1;;
     3)echo "You have Quit the program. To begin again type:- ./page1"
esac
echo
echo

Basically, a user is prompted to type a sed command that will interrogate a file they specify and based on criteria they specify. That information is then written to a new file that they give a name to. All of their responses are stored in variables, that are located in a function to be executed later on in the program.

I think the problem lies in my sed syntax.

To test it I type this in the stages as set out by the program:-

Code:
1. sed (the command)
2. /Anderson/w (the criteria)
3. testfile (the file to be written to)
4. filetest(the file to be interrogated)

I have also tried:-
Code:
1. '/Anderson/w
2. testfile'

I get:-
Code:
sed: Couldn't open file : No such file or directory

Any syntax ideas?
Or any other advice as to what I am doing wrong?


Cheers,


trufla
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help writing script to read files names

Hi there, I am trying to do somehting similar, but on a wider scale. I am trying to write a script that would open the home directory, open the first (of 650) user's folder open the ?mail directory, which every user has Then I need the script to read each of the files and folder names with... (2 Replies)
Discussion started by: technett
2 Replies

2. Shell Programming and Scripting

Writing a shell script to untar files

I am new to shell scripting and would appreciate any help I can get. I need to write a Unix shell script that I will run whenever I have a tar file to uncompress(Korn shell). Please put in mind that I have different environements that I will run it on. Thanks in advance ;) (4 Replies)
Discussion started by: nkem22
4 Replies

3. UNIX for Dummies Questions & Answers

new to writing script files

thanks guys i managed to answer (0 Replies)
Discussion started by: bebop1111116
0 Replies

4. Shell Programming and Scripting

Problems writing bash script to unzip files

I'm getting the following errors when I try to write a script to unzip some zip files. When I use the free trial copy of the commerical winzip program, however, they work fine. When I use -l or -t on unzip it indicates no errors. When I use the -o switch interactively from the bash command line it... (1 Reply)
Discussion started by: siegfried
1 Replies

5. Shell Programming and Scripting

writing script in UNIX for copying files in two server

can anyone help me in writing script in UNIX for copying files in two server from the third server after checking the files in the third server and if there is anything new in the third server automatically it should be added to the rest of the two servers and if same file is existing in the two... (4 Replies)
Discussion started by: REKHA09
4 Replies

6. Shell Programming and Scripting

Need help in writing script for finding files in the unix machine?

I would like to find whether a file exists in the UNIX machine. That i can check using if ;then echo "exists" echo " `cat $file` " else echo "invalid file" fi. and i can find out using : find / -name "filename" . But it i have wanted to search in all directories. How to get... (3 Replies)
Discussion started by: rparsa001
3 Replies

7. UNIX for Dummies Questions & Answers

Writing awk script to read csv files and split them

Hi Here is my script that calls my awk script #!/bin/bash set -x dir="/var/local/dsx/csv" testfile="$testfile" while getopts " f: " option do case $option in f ) testfile="$OPTARG";; esac; done ./scriptFile --testfile=$testfile >> $dir/$testfile.csv It calls my awk... (1 Reply)
Discussion started by: ladyAnne
1 Replies

8. Shell Programming and Scripting

Writing a Perl Script that processes multiple files

I want to write a Perl script that manipulates multiple files. In the directory, I have files 250.*chr$.ped where * is from 1 to 1000 and $ is from 1-22 for a total of 22 x 10,000 = 22,000 files. I want to write a script that only manipulates files 250.1chr*.ped where * is from 1 to 22.... (10 Replies)
Discussion started by: evelibertine
10 Replies

9. Shell Programming and Scripting

help with writing a awk/sed script

Hi, I thought I am getting pretty good with sed and awk, but now I dont have a way out of this question. I have a table 0.5 16 1.3 14 0.25 15 0.85 16 I want to make a column 3 which contains values that are (corresponding $2 value/sum of all $2). Please help me out here. Thanks. (6 Replies)
Discussion started by: jamie_123
6 Replies

10. UNIX for Dummies Questions & Answers

Writing a script to print the number of lines in multiple files

Hi I have 1000 files labelled data1.txt through data1000.txt. I want to write a script that prints out the number of lines in each txt file and outputs it in the following format: Column 1: number of data file (1 through 1000) Column 2: number of lines in the text file Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies
ECHO(3) 								 1								   ECHO(3)

echo - Output one or more strings

SYNOPSIS
void echo (string $arg1, [string $...]) DESCRIPTION
Outputs all parameters. echo is not actually a function (it is a language construct), so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function. Additionally, if you want to pass more than one parameter to echo, the parameters must not be enclosed within parentheses. echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syn- tax only works with the short_open_tag configuration setting enabled. I have <?=$foo?> foo. PARAMETERS
o $arg1 - The parameter to output. o $... - RETURN VALUES
No value is returned. EXAMPLES
Example #1 echo examples <?php echo "Hello World"; echo "This spans multiple lines. The newlines will be output as well"; echo "This spans multiple lines. The newlines will be output as well."; echo "Escaping characters is done "Like this"."; // You can use variables inside of an echo statement $foo = "foobar"; $bar = "barbaz"; echo "foo is $foo"; // foo is foobar // You can also use arrays $baz = array("value" => "foo"); echo "this is {$baz['value']} !"; // this is foo ! // Using single quotes will print the variable name, not the value echo 'foo is $foo'; // foo is $foo // If you are not using any other characters, you can just echo variables echo $foo; // foobar echo $foo,$bar; // foobarbarbaz // Some people prefer passing multiple parameters to echo over concatenation. echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10); echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . " "; echo <<<END This uses the "here document" syntax to output multiple lines with $variable interpolation. Note that the here document terminator must appear on a line with just a semicolon. no extra whitespace! END; // Because echo does not behave like a function, the following code is invalid. ($some_var) ? echo 'true' : echo 'false'; // However, the following examples will work: ($some_var) ? print 'true' : print 'false'; // print is also a construct, but // it behaves like a function, so // it may be used in this context. echo $some_var ? 'true': 'false'; // changing the statement around ?> NOTES
Note Because this is a language construct and not a function, it cannot be called using variable functions. SEE ALSO
print(3), printf(3), flush(3), Heredoc syntax. PHP Documentation Group ECHO(3)
All times are GMT -4. The time now is 10:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy