Linux redirect output to file question


Recommended Posts

Hello guys...

 

So let's say i do

cat ifcfg-eth? > test.txt

Now i have 3 different eth and i want that when the info goes into the file it will place space or some kind of a break between each eth info.

 

Can i do this?

 

 

Thanks

If this is something you do frequently on your machine, have you considered aliasing it? I have many aliases that allow me to do things faster, and I would absolutely create an alias for that command if I used it frequently.

 

Add something like the following to your ~/.bash_aliases or ~/.bashrc:

function catifcfg
{
    if [ -n "$1" ]; then
        outfile="$1"
    else
        outfile='test.txt'
    fi
    
    for infile in ifcfg-eth?; do
        cat $infile >> $outfile
        echo >> $outfile
    done
}

 

If this is something you do frequently on your machine, have you considered aliasing it? I have many aliases that allow me to do things faster, and I would absolutely create an alias for that command if I used it frequently.

 

Add something like the following to your ~/.bash_aliases or ~/.bashrc:

function catifcfg
{
    if [ -n "$1" ]; then
        outfile="$1"
    else
        outfile='test.txt'
    fi
    
    for infile in ifcfg-eth?; do
        cat $infile >> $outfile
        echo >> $outfile
    done
}

Thank you, it's a good idea to do it this way....  (Y)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

  • Recent Achievements

    • One Month Later
      timbobit earned a badge
      One Month Later
    • One Month Later
      nates earned a badge
      One Month Later
    • Week One Done
      Almohandis earned a badge
      Week One Done
    • Rookie
      dorf went up a rank
      Rookie
    • First Post
      mike_rumble earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      474
    2. 2
      +Edouard
      170
    3. 3
      PsYcHoKiLLa
      104
    4. 4
      Michael Scrip
      88
    5. 5
      Steven P.
      70
  • Tell a friend

    Love Neowin? Tell a friend!