Announcement

Collapse
No announcement yet.

Need help creating a bash alias

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Need help creating a bash alias

    I want to create a bash alias for this awk command:

    awk -F'@' '{gsub(/\./, "", $1); print $1 "@" $2}' gmail_block_log.csv > cleaned_email_addresses.txt

    My awk foo sucks, and Google isn't being very helpful. I know we have talent here in KFN, so, a little assistance please?
    Windows no longer obstruct my view.
    Using Kubuntu Linux since March 23, 2007.
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    #2
    add an alias to your ~/.bashrc.​
    the command contains quotes, it's easier to wrap the whole alias in double quotes and escape the $ signs​
    Code:
    alias cleanemails="awk -F'@' '{gsub(/\./, \"\", \$1); print \$1 \"@\" \$2}' gmail_block_log.csv > cleaned_email_addresses.txt"
    reload your shell:
    Code:
    source ~/.bashrc
    now simply run
    Code:
    cleanemails
    PS:Aliases are best for very short commands. Since this one is fairly complex, a function is easier to read and can later accept arguments...
    ʟɨռʊӼ ʄօʀ ʟɨʄɛ

    Comment


      #3
      Thank you. Geez. I though writing this alias would be 'harder' with the escapes and such. But it works perfectly just enclosed in quotes. By the way, I am quite familiar with bash aliases; I use them a lot. But there are times; and I thought this was going to be one of them; that some extra foo is required to translate a complex bash command line command into an alias.
      Last edited by Snowhog; Today, 06:55 AM.
      Windows no longer obstruct my view.
      Using Kubuntu Linux since March 23, 2007.
      "It is a capital mistake to theorize before one has data." - Sherlock Holmes

      Comment


        #4
        aliases have their limits

        i tried to write an alias for 'watch find -not \( -path './snap' -prune \) -not \( -path './.cache' -prune \) -type f -mmin -1 -printf "%C+ %p\n" | sort -n | tail -10'

        but ended up putting the watch command into a bash script and just calling the script with the alias.

        you can write a function directly into .bash_aliases, but i find it clutters up the file too much if gets complicated, so things are easier to manage in a collection of scripts.
        some stuff i did: https://github.com/droidgoo

        Intel® Core™ i7-14700K | 64 GiB of RAM | AMD RX 6800

        Comment

        Users Viewing This Topic

        Collapse

        There are 0 users viewing this topic.

        Working...
        X