Home > Mobile >  How to display a text file whose first line is displayed in uppercase, while the remaining lines are
How to display a text file whose first line is displayed in uppercase, while the remaining lines are

Time:05-30

tr a-z A-Z < items.txt

The above command can convert the text file to UPPER CASE, but I want the command that converts the first line only, leaving the other lines untouched.

CodePudding user response:

Both of the commands given in the comments work.

Shawn's solution:

$ echo -e 'one\ntwo\nthree' | sed '1s/.*/\U&/'
ONE
two
three

glenn jackman's solution:

$ echo -e 'one\ntwo\nthree' | awk 'NR == 1 {$0 = toupper($0)} 1'
ONE
two
three

CodePudding user response:

in awk, rule #1 is that don't split unnecessary fields :

echo -e "one alpha apple\ntwo beta"    \
        " orange\nthree omicron durian" | 

{m,g}awk -F'^$' 'NF<NR || $_=toupper($_)'

ONE ALPHA APPLE
two beta orange
three omicron durian
  • Related