Can I use awk to convert all the lower-case letters into upper-case?
Try this: awk ‘{ print toupper($0) }’ <<< “your string” Using a file: awk ‘{ print toupper($0) }’ yourfile.txt
Try this: awk ‘{ print toupper($0) }’ <<< “your string” Using a file: awk ‘{ print toupper($0) }’ yourfile.txt
try this short thing: awk ‘!($3=””)’ file
Besides the awk answer by @Jerry, there are other alternatives: Using cut (assumes tab delimiter by default): cut -f32-58 foo >bar Using perl: perl -nle ‘@a=split;print join “\t”, @a[31..57]’ foo >bar
Here is a solution using sed: $ sed -n ‘H;${x;s/^\n//;s/nameserver .*$/nameserver 127.0.0.1\n&/;p;}’ resolv.conf # Generated by NetworkManager domain dhcp.example.com search dhcp.example.com nameserver 127.0.0.1 nameserver 10.0.0.1 nameserver 10.0.0.2 nameserver 10.0.0.3 How it works: first, suppress the output of sed with the -n flag. Then, for each line, we append the line to the hold space, separating … Read more
The $URL contains a \r (CR) at the end (0d). Remove it with URL=${URL%$’\r’} before using it with curl.
I’m looking for a way to truncate a line at 80 characters … You could pipe the output to cut: printf … | cut -c 1-80 If you wanted to ensure that each line isn’t more than 80 characters (or wrap lines to fit in specified width), you could use fold: printf … | fold … Read more
sed -i ‘/^$/d’ foo This tells sed to delete every line matching the regex ^$ i.e. every empty line. The -i flag edits the file in-place, if your sed doesn’t support that you can write the output to a temporary file and replace the original: sed ‘/^$/d’ foo > foo.tmp mv foo.tmp foo If you … Read more
If you want to provide the pattern through a variable, you need to use ~ to match against it: awk -v pat=”$pattern” ‘$0 ~ pat’ In your case, the problem does not have to do with -F. The problem is the usage of /pat/ when you want pat to be a variable. If you say … Read more
The comparison with “” should have worked, so that’s a bit odd As one more alternative, you could use the length() function, if zero, your variable is null/empty. E.g., if (length(val) == 0) Also, perhaps the built-in variable NF (number of fields) could come in handy? Since we don’t have access to your input data … Read more
This line should do it: sed -e “s/\b\(.\)/\u\1/g”