scripting - Writing to a file through a bash script -


i want write bash script takes 2 arguments, a , b. based on argument, writes in section a or section b of text file.

output file txt file this:

common content.... section a: <everything should written here when specify option "a"> section b: <everything should written here when specify option "b"> 

i new bash.

#!/bin/bash   if [ "$#" -eq 2 ];then  seca="$1"  secb="$2" elif [ "$#" -eq 1 ];then  seca="$1" fi  awk -v s1="$seca" -v s2="$secb" ' /section a/ && s1{   $0=$0"\n"s1   while(getline line){    if (line~/section b/) { $0=$0"\n"line;break}   } } /section b/ && s2{ $0=$0"\n"s2} 1' file 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -