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
# 8  
Old 05-04-2017
Quote:
Originally Posted by Gurdza32
I am writing the shell on notepad
First off: you shouldn't. UNIX (any UNIX, including Linux) has a different way of separating text lines in a file , compared to Windows (any Windows-version). If you use (Windows-)notepad.exe to write a file chances are you can't run it on Unix wiht some processing so you will be on the safer side writing the file with a UNIX-based editor on the system itself instead.

Quote:
Originally Posted by Gurdza32
called valsplit.sh, when running the script in the ubuntu terminal I am required to...
OK, but: show us the script! how are we supposed to tell you what is wrong with your script when we haven't seen it yet? Post the content of said valsplit.sh and we will perhaps be able to tell you why it doesn't do what it should. Then you can correct it until it is working. But without having seen it we are like doctors who - instead of examining a patient - are just called by one with the information "it hurts". The reason for this can be everything and then some.

Quote:
Originally Posted by Gurdza32
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.
OK. Lets for now assume the thread is legitimate here. We still haven't seen your code and as long as that has not been changed we can't help you. So please post your code (put it in CODE-tags!!) and on we go.

I hope this helps.

bakunin
# 9  
Old 05-04-2017
This might be a start:
Code:
#!/bin/bash
# cycle through the arguments
for input in "$@"
do
  err=""
  linenr=0
  # cycle through each line
  while read line
  do
    ((linenr++))
    case $line in
    (*a*)
      : do nothing
    ;;
    (*)
      err="No 'a' in line $linenr"
    ;;
    esac
  done < "$input"
  if [ -n "$err" ]
  then
    echo "${err}, file $input not copied"
  else
    : copy $input
  fi
done

Please try to understand it, and modify it according your needs.
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