I am trying to run a bash analysis script on my mac but the sed command is not recognising '~'. The script works perfectly on my linux workstation. My script looks like this;
#!/bin/bash
sed -n '3~9p' file.txt | awk '{print $2}' > out.dat
When I run this on my mac I get "sed: 1: "3~9p": invalid command code ~".
You can try this awk
instead of sed
,
awk 'BEGIN {s=3;i=9} NR==s{s+=i;print}' file.txt
Even more straight forward way is,
awk 'BEGIN {s=3;i=9} NR==s{s+=i;print $2}' file.txt > out.dat
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments