Reading a file passed as an argurement and assessing the files syntax


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading a file passed as an argurement and assessing the files syntax
# 1  
Old 05-04-2017
Reading a file passed as an argurement and assessing the files syntax

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being read follows the syntax then it should be sent to another file called correct.txt if the syntax is incorrect of the line then it should be sent to incorrect.txt. I have been struggling to get the shell script to read the file and then assess the syntax. Please could someone help
# 2  
Old 05-04-2017
Without seeing your script it will be difficult...
What kind of syntax is it trying to check? your own rules?
# 3  
Old 05-04-2017
Quote:
Originally Posted by vbe
Without seeing your script it will be difficult...
What kind of syntax is it trying to check? your own rules?
They are rules I have been given as requirements for example, line 1 in the txt file is add $s0 $s1 $s2. The shell script is then supposed to view the line of text and run a check to see if there is an add or sub in the line of text, if there is does it have 3 arguments after it.

---------- Post updated at 10:25 AM ---------- Previous update was at 10:19 AM ----------

Quote:
Originally Posted by vbe
Without seeing your script it will be difficult...
What kind of syntax is it trying to check? your own rules?
Is it possible for you to email me, so I can send you some more information? gurdza_pol@hotmail.com
# 4  
Old 05-04-2017
Hello!

In case you forgot to read the forum rules, do not send a private message with a technical question. The forums are for the benefit of all, so all Q&A should take place in the forums.

Quote:
RULES OF THE UNIX AND LINUX FORUMS


(1) No flames, shouting (all caps), sarcasm, bullying, profanity or arrogant posts.

(2) No negative comments about others or impolite remarks. Be patient.

(3) Refrain from idle chatter that does not contribute to the knowledge base. This does not apply to the forums in The Unix Lounge which are for off-topic discussions.

(4) Do not 'bump up' questions if they are not answered promptly. No duplicate or cross-posting and do not report a post or send a private message where your goal is to get an answer more quickly.

(5) Search the forums database with your keywords before asking.

(6) Do not post classroom or homework problems.

(7) No job postings from headhunters or recruiters except in The Unix Forums Job Board. See How to Post to The UNIX Forums Job Board for information on using the Job Board.

(8) No BSD vs. Linux vs. Windows or similar threads.

(9) Edit your posts if you see spelling or grammar errors (don't write in cyberchat or cyberpunk style). English only.

(10) Don't post your email address and ask for an email reply. Don't send a private message with a technical question. The forums are for the benefit of all, so all Q&A should take place in the forums.

(11) Post questions with descriptive subjects. For example, do not post questions with subjects like "Help Me!", "Urgent!!" or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".

(12) These are not hacker boards so hacker related posts will be promptly deleted or moderated.

(13) The forum administrators reserve the right to prune, move or edit posts that do not adhere to the rules or are technically inaccurate.

(14) The forum administrators reserve the right to remove users or change their posting status to read only without notice if any rules are not followed.

(15) No smoking in the forums.
Users who break the rules are generally banned from the site, so please follow the rules.

Thanks.


The UNIX and Linux Forums
# 5  
Old 05-04-2017
Sorry I am new to the site and was not aware of the rules
# 6  
Old 05-04-2017
Please become accustomed to provide decent context info of your problem.
It is always helpful to support a request with system info like OS and shell, related environment (variables, options), preferred tools, and adequate (representative) sample input and desired output data and the logics connecting the two, to avoid ambiguities and keep people from guessing.

Open questions: input file format, how do you convey the rules, ans preferred tools?

And, is that homework or classwork?
# 7  
Old 05-04-2017
Quote:
Originally Posted by RudiC
Please become accustomed to provide decent context info of your problem.
It is always helpful to support a request with system info like OS and shell, related environment (variables, options), preferred tools, and adequate (representative) sample input and desired output data and the logics connecting the two, to avoid ambiguities and keep people from guessing.

Open questions: input file format, how do you convey the rules, ans preferred tools?

And, is that homework or classwork?
I am writing the shell on notepad called valsplit.sh, when running the script in the ubuntu terminal I am required to supply 3 arguments a .txt file to read information from and 2 more .txt files to send information to. The file to be read is called input.txt it contains lines of text similar to an example I provided above. They are to be read and validated one line at a time. First we are to check if at the start of the line there is the word "add", "sub", "addi", "lw" or "sw". If that passes the test next is to check if the "add" or "sub" has 3 arguments after it containing either a t or an s, they must also have a $ before it. If the command addi is used one of the arguements must be within a certain number range. If they pass the checks they should be sent to the correct.txt file which is the second argument when running the script in the terminal. If they do not pass the checks the line must be to the third argument in the terminal which is the incorrect.txt file and a message should be output to the terminal stating the error.

This is a practice task for revision I am having trouble with setting up the shell script in notepad, creating a while loop to read each line of the input.txt file and the if statements to check the syntax also I am having trouble using the terminal.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

3. Shell Programming and Scripting

reading files and pasting in another text file

Hi all, I have certain task to do, which involves reading the first column of 1.txt file. This is variable "event" 28434710 23456656 3456895 & finding this "event" in some other text file 2.txt, which has information in the following format #Zgamma: 1 run: 160998 event: ... (7 Replies)
Discussion started by: nrjrasaxena
7 Replies

4. Shell Programming and Scripting

Reading files under a folder and formatting content of each file

I have 'n' number of files in a folder .each file in the folder "myfolder" is having the content like. COLNAME ------------ AAAAAA BBBBBB CCCCCC DDDDDD ... ... ... ZZZZZZ 26 recrod(s) selected. My request is by reading each file in "myfolder" and format each file such a way... (18 Replies)
Discussion started by: rocking77
18 Replies

5. Shell Programming and Scripting

Recommended reading to understand syntax

Do you have any recommendations for books to read or websites to visit that cover syntax information about when to use square brackets, brackets, braces, apostrophes, quotation marks etc. in a shell script. I have little troubling on the command line but it all goes to pot when I am coding shell... (2 Replies)
Discussion started by: SusanDAC
2 Replies

6. UNIX for Dummies Questions & Answers

Ksh Storing Multiple Files and reading each line in each file.

How would I go about storing multiple file paths in a directory that begin like: 20080402* and run a loop that reads each line of each file thats in a given directory. So far this is what I have: #!/bin/ksh echo "ENTER Reprint Date (YYYYMMDD): " read ReprintDate echo ""... (1 Reply)
Discussion started by: developncode
1 Replies

7. Shell Programming and Scripting

How to get files names passed to a script

I need to get files names passed to a script. Here number of files passed may vary like MyScript.ksh file1 file2 file3..... so on I am writting script somthing like this set -A Files while (i<=$#) do File=$i let i=i+1 done Is this correct way doing this. Is there any other way.... (5 Replies)
Discussion started by: unishiva
5 Replies

8. Shell Programming and Scripting

reading a file name as soon as that files arrives into a folder

Hi, Thanks in Advance.. i have the following requirement, some one please help me.. An unix shell script has to pick up the file name from a folder as soon as that file comes into that folder. Regards, Alo (6 Replies)
Discussion started by: dtazv
6 Replies

9. UNIX for Advanced & Expert Users

how to configure the lp system to filter files passed to it

I registered a printer hp123 on Sun Solaris Server. I think my printer is expecting a carriage return and linefeed combination at the end of each line (DOS standard), but unix files only have linefeeds at the end of each line. How can I configure the lp system to filter files passed to it?... (1 Reply)
Discussion started by: simt
1 Replies
Login or Register to Ask a Question