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
COLORS(3)						   libbash colors Library Manual						 COLORS(3)

NAME
colors -- libbash library for setting tty colors. SYNOPSIS
colorSet <color> colorReset colorPrint [<indent>] <color> <text> colorPrintN [<indent>] <color> <text> DESCRIPTION
General colors is a collection of functions that make it very easy to put colored text on tty. The function list: colorSet Sets the color of the prints to the tty to COLOR colorReset Resets current tty color back to normal colorPrint Prints TEXT in the color COLOR indented by INDENT (without adding a newline) colorPrintN The same as colorPrint, but trailing newline is added Detailed interface description follows. Available colors: Green Red Yellow White The color parameter is non-case-sensitive (i.e. RED, red, ReD, and all the other forms are valid and are the same as Red). FUNCTIONS DESCRIPTIONS
colorSet <color> Sets the current printing color to color. colorReset Resets current tty color back to normal. colorPrint [<indent>] <color> Prints text using the color color indented by indent (without adding a newline). Parameters: <indent> The column to move to before start printing. This parameter is optional. If ommitted - start output from current cursor position. <color> The color to use. <color> The text to print. colorPrintN [<indent>] <color> The same as colorPrint, except a trailing newline is added. EXAMPLES
Printing a green 'Hello World' with a newline: Using colorSet: $ colorSet green $ echo 'Hello World' $ colorReset Using colorPrint: $ colorPrint 'Hello World'; echo Using colorPrintN: $ colorPrintN 'Hello World' AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), libbash(1) Linux Epoch Linux
All times are GMT -4. The time now is 06:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy