Learn three approaches for awk to print records in the same line with examples.
Baeldung Author
Kai Yuan
Kai Yuan has been a software developer for over 15 years. He builds enterprise Java applications in work. He has 20 years experience of Linux and is a big fan of the Vim editor. He is happy to help people at stackoverflow.com. He lives currently in Hamburg.
Here's what I've written (so far):
Baeldung on Linux
- All
- Files (52)
- Scripting (36)
- File Editing (20)
- Administration (15)
- Processes (9)
- File Searching (8)
- Filesystems (6)
- File Viewing (4)
- Search (3)
- File Permissions (3)
- Web (2)
- Security (1)
- File Compression (1)
How to Filter strace’s Output Using grep
Filed under Administration, Processes, Scripting
Learn how to use the grep command to filter strace’s output.
Matching Multiple Strings Using Only One grep
Filed under Files
Learn how to search multiple strings using only one grep process
Returning Filenames Without Extension Using find
Filed under Files
Learn how to tell find to output only filenames without extensions.
How to Process a Bash Variable With sed
Filed under Scripting
Learn three approaches to using an external command to process shell variables
How to Sum Up the Size of Files Listed
Filed under Files
Learn how to sum up the size of listed files using the ls and find commands
Find Statistics on File Types Recursively in a Directory
Filed under Files
Learn two methods to recursively find statistics on file types in a directory
How to Use which on an Aliased Command
Filed under Administration, Scripting
Learn how to get an executable’s path when it’s in an alias
Command-Line Tools for Printing a Blank Line Between Lines of a Text File
Filed under File Viewing
Learn how to output a blank line after each line in the file using Linux command-line tools.
Implementing a Command Line Progress Bar
Filed under Scripting
Learn how to implement a customizable, reusable command line progress bar using shell script.
Setup a Ruler on a Specific Column in Vim
Filed under File Editing
Learn how to set column rulers in the Vim editor and customize them.
How to Make Output Overwrite the Same Line in a Terminal
Filed under Scripting
Explore how to overwrite an output line using the echo and printf commands.
Use grep to Show Only Filenames on Linux
Filed under Files
Learn how to list only the names of the files that match the given pattern.
Get Username by User ID in Linux
Filed under Administration
Learn how to find the user’s name by a given UID
How to grep the ps Output With Headers
Filed under Processes
Learn how to find desired processes and preserve the header line of ps’s output.
Find Processes by Keyword in Linux
Filed under Processes
Learn how to find processes’ information by a keyword.
How to Check Cron Logs in Linux
Filed under Administration
Learn how to check the cron jobs’ logs for two common cron implementations and two different logging systems.
List Only Non-Empty Files in Linux
Filed under Files
Learn how to use the find command to list non-empty files under a directory
Recall the Previous Command or Its Arguments in Bash
Filed under Scripting
Learn some tricks to reuse different parts from the last command in Bash
When to Avoid Using && in Shell Scripts
Filed under Scripting
Start from a script example and discuss a case we should avoid using && when writing shell scripts
Remove Duplicate Lines from a File Without Sorting
Filed under Files
Learn how to use awk to remove duplicate lines from an input file
Get the Current User in Linux
Filed under Administration
Learn how to identify the current user in Linux
Adding a Column of Values in a Tab Delimited File in Linux
Filed under File Editing
Learn how to add a new column to a given TSV file in the Linux command line
Get the Name of a Process from PID
Filed under Processes
Explore how to get the process name by a given PID
Concatenate String Variables in Bash
Filed under Scripting
Learn how to use Bash’s += operator and parameter expansion to concatenate variables
Difference Between Sourcing and Executing a Shell Script
Filed under Scripting
Learn the difference between sourcing a script and executing a script in Linux through examples
Quickly Clear the Contents of a File in Linux
Filed under File Editing
Learn how to clear only a file’s content from the Linux command line and keep the empty file
Bash Command to Check if Oracle or OpenJDK is Installed
Filed under Administration
Learn how to check if the current Java environment is Oracle JDK or OpenJDK
Split a List by Comma in Bash
Filed under Scripting
Learn how to parse CSV format data in Bash through examples
Find Matching Text and Replace the Next Line
Filed under File Editing, File Searching
Learn how to search a pattern and apply some text substitution in the next line using sed and awk
Using grep After a Specified Line Number
Filed under File Viewing
Learn three approaches to search for a pattern in a file, starting after a given line number
How to Specify More Spaces as the Delimiter Using cut
Filed under Files
Learn two approaches to extracting fields from input when the delimiter is multiple spaces
List Files in a Zip Archive Without Decompressing
Filed under File Compression
Learn how to list the files in a Zip archive without decompressing it
Why Is \d Not Supported by grep’s Regex
Filed under File Searching
Learn why Regex \d isn’t supported by Linux commands such as grep and sed
Substitute Shell Variables in a Text File
Filed under Administration, Scripting
Learn how to substitute shell variables with their values in a text file in the Linux command line
Use grep to Find Content in Files and Move Matched Files
Filed under Files
Learn three approaches using grep to search files and move the found files to a directory in one shot
The /bin/true and /bin/false Commands in Linux
Filed under Scripting
Take a closer look at the /bin/true and /bin/false commands with some use cases
grep in a tar.gz Archive
Filed under File Searching
Learn how to do grep on a tar.gz archive to find which files contain an interesting pattern
How to Swap Two Files in the Linux Command Line
Filed under Files
Learn how to swap two files’ content using three mv commands
Round a Divided Number in Bash
Filed under Scripting
Learn how to perform various rounding methods in Bash
Set Environment Variables for a Bash Command
Filed under Scripting
Learn how to set environment variables only for one single command
Show Only the N-th Line After the Match
Filed under File Viewing
Learn how to only print the n-th line after the match using grep, sed, and awk
Return Value of Substitutions With sed and awk
Filed under Scripting
Learn how to return different values from sed and awk depending on the substitution result
xargs With Multiple Arguments
Filed under Scripting
Learn how to use the xargs command to handle multiple arguments
tar Files of Certain Types
Filed under Files
Learn how to use the find and tar commands to archive files of certain types
Use sudo Command in Non-Interactive Mode
Filed under Administration
Learn approaches to run a command as the superuser without asking for a password
Skip Hidden Files and Directories During Recursive Copy
Filed under Files
Learn how to copy directories recursively while excluding hidden files and directories
Linux – wget Timeout
Filed under Web
Take a closer look at wget’s timeout settings
Check if a Library is 32-Bit or 64-Bit
Filed under Files
Our Linux distro may contain a mixture of 32 and 64 bit libraries. We can find out the architecture the library was built for by using a couple of commands. We explore how to do this for static and shared libraries.
List One Filename Per Line in Linux
Filed under Files
Learn how to use the ls command to list one file per line
Including Additional Files in .bashrc
Filed under Administration
Learn how to include additional scripts in the .bashrc file through examples
Insert a Line With Spaces Using sed
Filed under File Editing, Files
Take a closer look at how to use the sed command’s feature for inserting a new line when the new line contains spaces
Get the Last Word From Each Line
Filed under Files
Learn two ways to get the last word from each line of a file
Get CPU Usage of One Single Process Periodically
Filed under Processes
Learn how to build simple shell scripts to log the CPU usage of a single process
The Last Modification Time of a Directory
Filed under Files
Learn how to get a directory’s last modification time and what changes to a directory will affect the modification time
Merge Two Files Line By Line in Linux
Filed under File Editing, Files
Learn how to column-wise combine two input files through examples
Split a File With the Header Line
Filed under File Editing, Files
Learn how to split an input file with the header line using the split and awk commands
Remove All Whitespace Characters From a Text File
Filed under File Editing, Files
Commands That Will Open a URL in the Default Browser
Filed under Web
Learn several ways to open a URL in the default browser from the Linux command line
Linux: Delete Files Listed in a File
Filed under Files
Learn how to delete files listed in another file using pure Bash, xargs, sed, and awk
Delete All Lines in a File Starting From a Specific Line
Filed under File Editing, Files
Learn how to delete lines from a given line number until the end of the file using head, sed, and awk
Read a Specific Line From a File in Linux
Filed under Files
Learn different approaches to read a specific line from a file
Get the Last Directory or Filename From a File Path
Filed under Files
Learn how to extract the last component from a given path string
Identify User in a Bash Script Called by sudo
Filed under Scripting
Learn two different ways to get the current login user in the shell script and a few common pitfalls
Extracting a Substring in Bash
Filed under Scripting
Learn various ways to extract substrings using the Linux command line
How to Copy a Directory to an Existing Directory in Linux
Filed under Files, Filesystems
Learn how to recursively copy a directory to an existing directory with or without overwriting
Redirect Output to Location With “Permission denied” Error
Filed under File Permissions
Learn how to overcome the “Permission denied” error when redirecting output to a file.
Remove the Last Character From Each Line in Linux
Filed under File Editing, Files
Learn how to remove the last character from all lines in a file through examples
How to Remove Symbolic Links
Filed under Administration, Filesystems
Learn how to remove a symbolic link using the rm and unlink commands
Preserve Linebreaks When Storing Command Output to a Variable
Filed under Scripting
See why linebreaks in a shell variable can disappear in echo’s output and learn the right way to use shell variables in commands
Find and Delete Files and Directories
Filed under File Searching, Files
Learn three different ways to delete files or directories found by the find command
Using grep on Files That Match Specific Criteria
Filed under File Searching, Files
Learn how to execute grep on a set of filtered files
Print Lines Between Two Patterns in Linux
Learn how to extract data lines between two patterns.
How to Create Soft Links to Directories
Filed under Filesystems
Learn how to create soft links to directories through examples
List All Groups in Linux
Filed under Administration
Learn two approaches to get all groups defined on the system
Copy Directory Structure Without Files
Filed under Filesystems
Learn three different ways to clone a directory structure without copying files under it through examples
Copy and Create Destination Directory if it Does Not Exist
Filed under Filesystems
Learn how to create the non-existing target directory automatically when we copy files
Find Files Not Owned by a Specific User in Linux
Filed under File Searching, Files
Learn how to search for files not owned by a particular user using the find command
Changing the Default Shell in Linux
Filed under Administration
Learn how to change a user’s default shell through examples
Linux Bash: Multiple Variable Assignment
Filed under Scripting
Take a closer look at how to do multiple variable assignment in Bash scripts
Showing a GUI Notification From a Shell Script in Linux
Filed under Scripting
Learn how to send a GUI notification from a shell script using notify-send and zentity
sed Substitution With Variables
Filed under File Editing, Files
Take a closer look at some common mistakes made using sed substitution with shell variables
Evaluate XPath in the Linux Command Line
Filed under File Searching, Files
Learn how to evaluate XPath expressions using xmllint, XMLStarlet, and xidel
Using sed With a Literal String Instead of an Input File
Filed under Scripting
Have a look at how to use the sed command to process a literal string or shell variable.
Remove the First Line of a Text File in Linux
Filed under File Editing, Files
Learn how to remove the first line from using sed, awk, and tail
Using Vim Registers
Filed under File Editing, Files
Learn about each type of Vim register through examples
How to Remove the Lines Which Appear in File B From Another File A in Linux
Filed under File Editing, Files
Learn several approaches to remove the lines that appear in file B from another file A
Remove the Last N Lines of a File in Linux
Filed under File Editing, Files
Learn different ways to remove the last n lines from an input file and the performance of those approaches
Splitting a File at Given Line Numbers
Filed under File Editing, Files, Scripting
Learn how to split a file at given line numbers using head, tail, sed, and awk
How to Delete Multiple Files at Once in Bash
Filed under Scripting
Learn how to delete multiple files in one shot from the Linux command line
Run a Function in a Script from the Command Line
Filed under Scripting
Learn how to call shell script functions from outside the shell script file
Count Duplicated Lines in a Text File
Filed under Files
Learn a few ways to count repeated lines in a text file
Implement a Counter in Bash Script
Filed under Scripting
Learn how to implement a counter in a Bash script and some common pitfalls
Save Modifications In-Place with awk
Filed under Scripting
Learn how to do in-place editing with the awk command through examples
Recursive Search and Replace in Text Files
Filed under File Editing, Files, Search
Learn how to search and replace in text files recursively through examples
Easy Ways to Determine Virtualization Technology
Filed under Administration
Learn how to determine virtualization technology using Linux commands
Send stdout to Multiple Commands
Filed under Scripting
Learn how to send the output of a command to multiple commands using three different solutions through examples
How to Print the Longest Line(s) in a File
Filed under Files
Learn different ways to find the longest lines from an input file and benchmark their performance
How to Pretty-Print XML From the Command Line
Filed under File Viewing, Files
Learn several ways to pretty-print an XML file using Linux commands
Reading Output of a Command Into an Array in Bash
Filed under Scripting
Learn a few ways to save multi-line output into a Bash array
How to Show All Shared Libraries Used by Executables in Linux?
Filed under Processes
Learn several ways to list all shared libraries used by a program
How to Call an External Program Using awk
Filed under Scripting
Learn how to call an external program using awk
Linux Job Control: &, disown, and nohup
Filed under Processes
Learn about three common approaches to start a process and let it run in the background as a job
How to Randomize Lines in a File in Linux
Filed under Files
Compare different ways to shuffle lines in text and discuss their pros and cons
Remove Blank Lines From a File
Filed under File Editing, Files
Explore some common scenarios for removing blank lines from a file through practical examples
How to Join Multiple Lines Into One
Filed under Scripting
Learn several ways to merge multiple lines of input into a single line with customized delimiters
Process Multiple Input Files Using Awk
Filed under Files
Learn how to process multiple input files using the awk command using simple examples
Linux last Command
Filed under Administration
Learn how to get login related information using the last and lastb commands
Shut Down and Reboot Linux Systems From the Terminal
Filed under Administration
Learn some useful commands to reboot and shut down a Linux system from the command line
Is There a Way to ‘uniq’ by Column?
Filed under Scripting
Learn how to do the “uniq” operation on a column instead of the entire line
date Command in Linux
Filed under Scripting
We’ll take a closer look at the date utility and learn its common usages
The head and tail commands in LINUX
Filed under File Editing, Files
Learn about the typical usages of the head and tail command through examples.
Linux watch Command
Filed under Scripting
Learn how to use the watch command to execute a command periodically and check the output of each execution
The echo Command in Linux
Filed under Scripting
Learn the echo command and its options through examples
Linux sort Command
Filed under Files
Learn the sort command through various examples
Advanced File Permissions in Linux
Filed under File Permissions, Files, Security
Learn about special file permission flags in Linux
Linux tr Command
Filed under Files
Learn how to use the tr command through various examples
Introduction to File Locking in Linux
Filed under File Permissions, Files
Learn about two types of file locks in Linux some related commands through examples
Introduction to File MIME Types
Filed under Files
Learn about MIME types and how to get the MIME type of a file using Linux command-line utilities
Renaming Linux Files in Batches
Filed under Files
Depending on the Linux distro and use case, there are a few available tools that can rename a batch of files. We explore some common use cases.
Finding the PID of the Process Using a Specific Port
Filed under Processes
Learn different approaches to finding the process listening on a particular port in Linux
How to Mount and Unmount Filesystems in Linux
Filed under Filesystems
Learn how to use the Linux mount command to attach various filesystems and detach them with umount
Guide to Useful File Manipulation Commands
Filed under File Editing, Files
Learn about some useful file manipulation commands in Linux.
Common Linux Text Search
Filed under File Searching, Files, Search
Learn how to perform some common text searching in Linux using the grep command-line utility
Often we need to remove whitespace from files in Linux. This needs special processing if we want to include Unicode or line breaks. We look at how to solve this with a few common command line tools.