Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

awk

Insert a line at specific line number with sed or awk

October 18, 2022 by Tarik

sed -i ‘8i This is Line 8’ FILE inserts at line 8 This is Line 8 into file FILE -i does the modification directly to file FILE, no output to stdout, as mentioned in the comments by glenn jackman.

Categories sed Tags awk, sed Leave a comment

bash: shortest way to get n-th column of output

October 16, 2022 by Tarik

You can use cut to access the second field: cut -f2 Edit: Sorry, didn’t realise that SVN doesn’t use tabs in its output, so that’s a bit useless. You can tailor cut to the output but it’s a bit fragile – something like cut -c 10- would work, but the exact value will depend on … Read more

Categories bash Tags awk, bash Leave a comment

How to grep for case insensitive string in a file?

October 16, 2022 by Tarik

You can use the -i flag which makes your pattern case insensitive: grep -iF “success…” file1 Also, there is no need for cat. grep takes a file with the syntax grep <pattern> <file>. I also used the -F flag to search for a fixed string to avoid escaping the ellipsis.

Categories bash Tags awk, bash, grep, sed, shell Leave a comment

awk without printing newline

October 15, 2022 by Tarik

awk ‘{sum+=$3}; END {printf “%f”,sum/NR}’ ${file}_${f}_v1.xls >> to-plot-p.xls print will insert a newline by default. You dont want that to happen, hence use printf instead.

Categories scripting Tags awk, newline, scripting Leave a comment

How to get the second column from command output?

October 14, 2022 by Tarik

Use -F [field separator] to split the lines on “s: awk -F ‘”‘ ‘{print $2}’ your_input_file or for input from pipe <some_command> | awk -F ‘”‘ ‘{print $2}’ output: A B C D

Categories shell Tags awk, ksh, shell Leave a comment

How can I quickly sum all numbers in a file?

October 10, 2022 by Tarik

You can use awk: awk ‘{ sum += $1 } END { print sum }’ file

Categories linux Tags awk, bash, linux, perl, shell Leave a comment

How to split a delimited string into an array in awk?

October 8, 2022 by Tarik

Have you tried: echo “12|23|11″ | awk ‘{split($0,a,”|”); print a[3],a[2],a[1]}’

Categories awk Tags awk Leave a comment

How to show only next line after the matched one?

October 5, 2022 by Tarik

you can try with awk: awk ‘/blah/{getline; print}’ logfile

Categories awk Tags awk, grep, sed Leave a comment

Using multiple delimiters in awk

October 4, 2022 by Tarik

The delimiter can be a regular expression. awk -F'[/=]’ ‘{print $3 “\t” $5 “\t” $8}’ file Produces: tc0001 tomcat7.1 demo.example.com tc0001 tomcat7.2 quest.example.com tc0001 tomcat7.5 www.example.com

Categories awk Tags awk, command-line, text-processing Leave a comment

What are the differences between Perl, Python, AWK and sed? [closed]

October 3, 2022 by Tarik

In order of appearance, the languages are sed, awk, perl, python. The sed program is a stream editor and is designed to apply the actions from a script to each line (or, more generally, to specified ranges of lines) of the input file or files. Its language is based on ed, the Unix editor, and … Read more

Categories python Tags awk, language-comparisons, perl, python, sed Leave a comment
Older posts
Newer posts
← Previous Page1 … Page19 Page20 Page21 Next →

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa