Using file partially for filenames

There are some commands that take file name and there are some case where you need to give file name. But there are some cases where you want to modify the file before passing it to the command. What do you do in these case’s?

I had a file containing huge amount of data and for some testing I wanted to pass only the first few lines of the file and not the complete file.  And since the file only accepted filename and would not take any input from the STDIN so only option was to create a file with the required data in a temporary file. So, I sat back to figure out some way to do it and finally found I can use this:

testcommand -f<(head -1 )

The “testcommand” parameter “-f” requires a filename. And here we are passing the file to the command after filtering it with head command. You can use any bash command inside the <() combination.

Enhanced by Zemanta

Script to get yourself some conkyrc files

Table of contents for conkyrc

  1. Get yourself some conkyrc files.
  2. Script to get yourself some conkyrc files
  3. Cont: Get yourself some more conkyrc files.

Continuing from where we left, here is a script that can do all this for you 🙂

curl http://ubuntuforums.org/showthread.php?t=281865\&page=$i | sed -n '/\\/pr/ p'| sed '// d'| sed 's##\n-----------------------------------\n\n\n#' >conkyrc
	dos2unix conkyrc
	cp conkyrc .test
	while [ $(wc -l .test|sed 's/[^0-9]//g') != 0 ]
	do
		sed -n '1,/------------------------/ p' .test|sed '$d' >conkyrc.$count
		diff .test conkyrc.$count |sed 's/^<.//'|sed '1, /---------------------/ d;2d'>.test
		((count++))
	done

This will create couple of conkyrc.files in the current directory. Each of these is one from the web-page that I mentioned earlier. So, enjoy….

Enhanced by Zemanta

Remove some path from the PATH variable temporarily.

How many times has it happened to you that you are working on some linux platform (like Fedora/Ubuntu/CentOS etc) and suddenly you see that you need to remove some path from the PATH variable so that a script is executed from some other path. It really difficult to do this if the path is too long and if you end up doing this couple of times. If that is the case, then the below script is for you 🙂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash -
#===============================================================================
#
#          FILE:  remove_path.sh
#
#         USAGE:  ./remove_path.sh
#
#   DESCRIPTION:  Add a path from the $PATH variable
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  <a class=\"zem_slink\" title=\"Amit Agarwal\" rel=\"me\" href=\"http://amit-agarwal.co.in\">Amit Agarwal</a> (AKA), [email protected]
#       COMPANY:  Individual
#       VERSION:  1.0
#       CREATED:  08/08/2010 02:26:16 PM IST
#      REVISION:  ---
#===============================================================================
if [[ $# < 1 ]]
then
echo \"Not enough arguments\"
exit -999
fi
unset PATH_ PATH1
export PATH_=($(echo $PATH|sed \'s/:/ /g\'))
for i in `seq 1 ${#PATH_}`
do
echo ${PATH_[$i]}
echo ${PATH_[$i]}|<a class=\"zem_slink\" title=\"Grep\" rel=\"wikipedia\" href=\"http://en.wikipedia.org/wiki/Grep\">grep</a> $1
if [ $? != 0 ]
then
PATH1=$PATH1:${PATH_[$i]}
PATH1=$(echo $PATH1|tr -d \'\\n\')
#echo $PATH1
else
echo \"Not adding ${PATH_[$i]}\"
fi
done
echo \"old path saved in $PATH_\"
export PATH=$PATH1

\"Enhanced