I need to have a script read the files coming in and check information for verification.
On the first line of the files to be read is a date but in numeric form. eg: 20080923 But before the date is other information, I need to read it from position 27. Meaning line 1 position 27, I need to get that number and see if it’s greater then another number.
I use the grep command to check other information but I use special characters to search, in this case the information before the date is always different, so I can’t use a character to search on. It has to be done by line 1 position 27.
The
sedcommand reads the first line of the file and thecutcommand chops out characters 27-34 of the one line, which is where you said the date is.Added later:
For the more general case – where you need to read line 24, for example, instead of the first line, you need a slightly more complex
sedcommand:The
-noption means ‘do not print lines by default’; the24pmeans print line 24; the24qmeans quit after processing line 24. You could leave that out, in which casesedwould continue processing the input, effectively ignoring it.Finally, especially if you are going to validate the date, you might want to use Perl for the whole job (or Python, or Ruby, or Tcl, or any scripting language of your choice).