1

How do I modify this line below to capture the content between two lines without the trailing line break?

interesting="$(awk "NR >= $first_line && NR <= $second_line" $file_path | base64 -w 0)"

I'm not sure if I should be looking to do this with awk, bash, or some other unix tool?

  • 5
    Can you give example to understand well? – asktyagi Jun 2 at 5:03
  • 2
    Example input, example of desired output, please. – steve Jun 2 at 9:14
  • Kindly provide.input Data – Praveen Kumar BS Jun 2 at 14:52
  • Expected output – Praveen Kumar BS Jun 2 at 14:52
1

You could do it like:

< "$file_path" awk -v x="$first_line" -v y="$second_line" '
  NR == x {printf "%s", $0; next}
  NR > x && NR <= y {printf "%s", ORS $0}' |
  base64 -w0
  • where do I put the $file_path ? – Andrew Wei Jun 2 at 23:26
  • @AndrewWei, as input to the pipeline (see edit). The can be done by passing the file path to awk so awk opens it instead of the shell, but that wouldn't work for some values of $file_path (that contain = for instance). You also forgot the quotes around the variable. – Stéphane Chazelas Jun 3 at 5:28

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.