jeudi 29 janvier 2015

Copy the first 2 lines from a file and then remove the lines


I need to process a file using a shell script. The file arrives with the data as well as some embedded information releavant to how it is processed. The file is in the following format;



  • email_address

  • system_area

  • item_number

  • item_number

  • item_number

  • item_number

  • and so on ...


The email_address is required to notify the user submitting the file that it has completed and the system_area indicates to the loading process where the file should be loaded. Therefore I am taking both these values into variables for use in the script. I am currently using 3 sed commands to get the info and then remove the lines;


var1=$(sed -n '1p' infile) var2=$(sed -n '1p' infile) sed -i '1,2d' infile

The above code works but I feel it is 'clumsy' and probably inefficient. Does anyone know of a way to achieve the same ends more elegantly/efficiently ?



Aucun commentaire:

Enregistrer un commentaire