0
echo -n "##### STATIONS? #######"
read station
awk -v input="$station" '
BEGIN {
        n = split(tolower(input), user)
        fmt = "%-4s\n"
}
    {print}
    /stab_site clear/ {
        for (i=1; i<=n; i++)
            printf fmt, "stab_site" user[i]
        exit
    }
' ./data > data_2

Let assume user's input: ankr ista for stations. After the execution of codes, in data file, after the "stab_site clear" line, user's input is written as follows;

stab_siteankr
stab_siteista

I need to give one space between "stab_site" and "station_ids" in the codes. I also need to write the lines after one space from the beginning of the line as follow;

stab_site ankr
stab_site ista
1

let split

printf fmt, "stab_site" user[i]
  • "stab_site" user[i] will make stab_sitenakr as there is no space after site
  • printf fmt, "stab_site" user[i] is turn to
  • print "%-4s\n" , stab_sitenakr which print left aligned stab_sitenakr

maybe you are looking for

printf fmt, "stab_site " user[i]

or (as per OP's request)

printf " %s %s\n", "stab_site", user[i]
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.