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

Link to comment
Share on other sites

for i in ifcfg-eth?;do cat $i >> test.txt ; echo >> test.txt; done

 

that should place a balnk line between each ifcfg entry in the test.txt file

Link to comment
Share on other sites

not that I can think of.

 

Is that not short enough by itself?

Link to comment
Share on other sites

It is, just a bit harder to remember :D 

 

That's o.k, thanks a lot for the help.....  (Y)

Link to comment
Share on other sites

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
}
Link to comment
Share on other sites

 

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)

Link to comment
Share on other sites

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

    • No registered users viewing this page.