Using file partially for filenames

2012-02-12 1 min read Bash Learning

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:

Continue reading

create SQL-statements from textfile with awk

2010-03-08 1 min read Linux

<a href="http://feedproxy.google.com/~r/Command-line-fu/~3/lz9uEhVxEEk/create-sql-statements-from-textfile-with-awk">create SQL-statements from textfile with awk

  <td>
    <div class="text codecolorer">
      $ $ awk \'{printf "select * from table where id = %c%s%c;\\n",39,$1,39; }\' inputfile.txt
    </div>
  </td>
</tr>
1

inputfile.txt is a space-separated textfile, 1st column contains the items (id) I want to put into my SQL statement.

39 = charactercode for single tick \’

    <td>
      <div class="text codecolorer">
        1 = first column
      </div>
    </td>
  </tr>
</table>

If inputfile.txt is a CSV-file separated by \”,\” use FS= to define your own field-separator:

Continue reading

7-deadly-linux-commands

2009-09-26 3 min read Linux

You want to learn about Linux, start from learning what not to do. <a href="http://www.junauza.com/2008/11/7-deadly-linux-commands.html" target="_blank">Here is one for the starting point.

So moral of the story is if someone asks you to do something and you dont know what that command will do, then dont do it. If your inner thing does not allow you not to do it, do it with all the care you can take. May be a backup and most importantly &#8221;DONT USE ROOT LOGIN IF U DONT HAVE REASON TO USE IT&#8221;. BTW there are couple of more articles on these kind of advices but the best way to save yourself is to educate yourself on the outcome of the command you are executing.

Continue reading
1