Sponsored Content
Top Forums Shell Programming and Scripting [Script] Conditions on parsing file Post 302771238 by amazigh42 on Wednesday 20th of February 2013 04:54:46 AM
Old 02-20-2013
[Script] Conditions on parsing file

Hello,

I open a new POST, i consider that this is resolved
https://www.unix.com/shell-programmin...nt-script.html
But i wish improve it.
In case 1, I would like to test the input file $1.
If $1 exist with no parameters but only comments, then send a message "Please..."
I tried somethings but no results.
Can you help me ?

Code:
#!/bin/bash
# set -vx

f1()    {
         echo $1 $2 $3 $4
        }


case $# in
        0)      echo -e "# comment1\n# comment2" > list_file
                read -p "Please fill in this list_file: "
                echo $REPLY
                ;;
        1)      [ -f "$1" ] || exit
                grep -v '^#' "$1" |
                        while read arg1 arg2 arg3 arg4
                                do f1 $arg1 $arg2 $arg3 $arg4
                                done
                ;;
        4)      echo -e "# comment1\n# comment2" > list_file
                echo $1 $2 $3 $4 >> list_file
                ;;
        5)      echo -e "# comment1\n# comment2" > $1
                f1 $2 $3 $4 $5 >> "$1"
                ;;

        *)      echo "error msg"; exit
esac

Have a nice day.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a file in Shell Script

Hi, I have a requirement. I have an application which can take a file as inputs. Now the file can contain any number of lines. The tool has to pick up the first uncommented line and begin processing it. For example the file could be like this: #MANI123|MANI1234 #MANI234|MANI247... (4 Replies)
Discussion started by: sendhilmani123
4 Replies

2. Shell Programming and Scripting

Help with script parsing a log file

I have a large log file, which I want to first use grep to get the specific lines then send it to awk to print out the specific column and if the result is zero, don't do anything. What I have so far is: LOGDIR=/usr/local/oracle/Transcription/log ERRDIR=/home/edixftp/errors #I want to be... (3 Replies)
Discussion started by: mevasquez
3 Replies

3. UNIX for Dummies Questions & Answers

Script for parsing details in a log file to a seperate file

Hi Experts, Im a new bee for scripting, I would ned to do the following via linux shell scripting, I have an application which throws a log file, on each action of a particular work with the application, as sson as the action is done, the log file would vanish or stops updating there, the... (2 Replies)
Discussion started by: pingnagan
2 Replies

4. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

5. Shell Programming and Scripting

parsing data for certain conditions

Hi guys, I have got this working OK but I am sure there is a more efficient/elegant way of doing it, which I hope you can help me with. It can be done in whatever is most suitable i.e perl/awk.. Any suggestions are welcome and many thanks in advance. What I require is to extract... (5 Replies)
Discussion started by: PAW
5 Replies

6. Shell Programming and Scripting

XML file parsing using script

Hi I need some help with XML file parsing. I have an XML file with the below tag, I need a script to identify the value of srvcName which is this case is "AAA srvc name". I need to put contents of this value which is AAA srvc and name into different variables using an array and then reformat it... (6 Replies)
Discussion started by: zmfcat1
6 Replies

7. Shell Programming and Scripting

Parsing file in perl script

Hi Guys, I have a large text file that is has a bunch of records. Each record starts with a header line that starts with the ">" character. Then there are several lines under that line that contain sequences of letters. For example, a file might look like: >TEXT ID=2L TEXT... (2 Replies)
Discussion started by: maverick.usb
2 Replies

8. Shell Programming and Scripting

Script for Parsing Log File

Working on a script that inputs an IP, parses and outputs to another file. A Sample of the log is as follows: I need the script to be able to input IP and print the data in an output file in the following format or something similar: Thanks for any help you can give me! (8 Replies)
Discussion started by: Winsarc
8 Replies

9. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

10. Shell Programming and Scripting

Script to change the file content using some conditions

Hello, I would like to change the content of the file that has few blocks starts with 10 and ends with ";" File1.txt 10 bonuses D 20 MATCHED 30 UPD COL 40 (SOL=30) 20 NOT MATCHED 30 INS COL 40 (SOL=30) ; 10 bonuses D 20 MATCHED 30 UPD COL 40... (5 Replies)
Discussion started by: Mannu2525
5 Replies
Test::Script(3) 					User Contributed Perl Documentation					   Test::Script(3)

NAME
Test::Script - Basic cross-platform tests for scripts DESCRIPTION
The intent of this module is to provide a series of basic tests for 80% of the testing you will need to do for scripts in the script (or bin as is also commonly used) paths of your Perl distribution. Further, it aims to provide this functionality with perfect platform-compatibility, and in a way that is as unobtrusive as possible. That is, if the program works on a platform, then Test::Script should always work on that platform as well. Anything less than 100% is considered unacceptable. In doing so, it is hoped that Test::Script can become a module that you can safely make a dependency of all your modules, without risking that your module won't on some platform because of the dependency. Where a clash exists between wanting more functionality and maintaining platform safety, this module will err on the side of platform safety. FUNCTIONS
script_compiles script_compiles( 'script/foo.pl', 'Main script compiles' ); The "script_compiles" test calls the script with "perl -c script.pl", and checks that it returns without error. The path it should be passed is a relative unix-format script name. This will be localised when running "perl -c" and if the test fails the local name used will be shown in the diagnostic output. Note also that the test will be run with the same perl interpreter that is running the test script (and not with the default system perl). This will also be shown in the diagnostic output on failure. script_runs script_runs( 'script/foo.pl', 'Main script runs' ); The "script_runs" test executes the script with "perl script.pl" and checks that it returns success. The path it should be passed is a relative unix-format script name. This will be localised when running "perl -c" and if the test fails the local name used will be shown in the diagnostic output. The test will be run with the same perl interpreter that is running the test script (and not with the default system perl). This will also be shown in the diagnostic output on failure. SUPPORT
All bugs should be filed via the bug tracker at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Script <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Script> For other issues, or commercial enhancement and support, contact the author. AUTHOR
Adam Kennedy <adamk@cpan.org> SEE ALSO
prove, <http://ali.as/> COPYRIGHT
Copyright 2006 - 2009 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.16.2 2009-11-23 Test::Script(3)
All times are GMT -4. The time now is 06:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy