PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How to save the output of this awk command to file?

 August 18, 2022     awk, linux, output     No comments   

Issue

I wanna save this command to another text: awk '{print $2}' it extract's from text. now i wanna save output too another text. thanks


Solution

awk '{ print $2 }' text.txt > outputfile.txt

> => This will redirect STDOUT to a file. If file not exists, it will create it. If file exists it will clear out (in effect) the content and will write new data to it

>> => This means same as above but if file exists, this will append new data to it.

Eg:

$ cat /etc/passwd | awk -F: '{ print $1 }' | tail -10 > output.txt
$ cat output.txt 
_warmd
_dovenull
_netstatistics
_avbdeviced
_krb_krbtgt
_krb_kadmin
_krb_changepw
_krb_kerberos
_krb_anonymous
_assetcache

Alternatively you can use the command tee for redirection. The command tee will redirect STDOUT to a specified file as well as the terminal screen

For more about shell redirection goto following link:

http://www.techtrunch.com/scripting/redirections-and-file-descriptors



Answered By - Suku
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing