Reese Knowledgebase

concatenate a file list into a string

View Kristian Reese's profile on LinkedIn

If you like this article, please +1 or Recommend via FB with the provided buttons above:

Article ID: 60
by: Reese K.
Posted: 17 Aug, 2012
Last updated: 19 Jul, 2013
Views: 1210

Example 1

kreese@myvps:arp $ cat ips
kreese@myvps:arp $
kreese@myvps:arp $ ips=$(< ./ips awk '$1')
kreese@myvps:arp $ echo $ips

Example 2:

nodevs=$(< /proc/filesystems awk '$1 == "nodev" { print $2 }')

Example 3:

One of my favorites is when I need to kill off a bunch of processes belonging to a specific user.  In comes in really handy when a customers VPS is hacked and they've created a privlidged user account where you want to quickly kill of a bunch of pids belonging to that user:

kill -9 $(ps -U 10000 | awk '{ print $1 }' | grep -v PID)

or use

ps -U apache -o pid --no-headers

Example 4:

Using tr

tr -s '\n' ' ' < file.txt

Example 5:

[root@vps11 ~]# for veid in $(cat vps5.migrations  | awk '{ print $4 }'); do echo -ne "$veid,"; done
7879,7868,11370,7843,8493,12116,13739,7915,7954,8640,[root@vps11 ~]#

This article was:   Helpful | Not Helpful
Prev   Next
Script for Log File Maintenance     crontab format