croussou
croussou

Reputation: 77

Save cat command output to file

I am saving the progress status of the git clone command using the below,

git clone --progress "https://giturl/repo.git" &> "/var/log/bitbucket.log

When using the cat command to see the contents of the file, such as

cat bitbucket.log

I get the below output, which is what I need,

Cloning into 'xyz'...
POST git-upload-pack (342 bytes)
remote: Counting objects: 2682, done.
remote: Compressing objects: 100% (1237/1237), done.
remote: Total 2682 (delta 1395), reused 2514 (delta 1316)
Receiving objects: 100% (2682/2682), 21.63 MiB | 10.32 MiB/s, done.
Resolving deltas: 100% (1395/1395), done.

However, when I open the file bitbucket.log, using nano, any other editor or directly from WinSCP, I get the following output,

Cloning into 'xyz'...
POST git-upload-pack (342 bytes)
remote: Counting objects: 2682, done.[K
remote: Compressing objects:   0% (1/1237)   [K
remote: Compressing objects: 100% (1237/1237), done.[K
Receiving objects:   0% (1/2682)
...
Receiving objects:  98% (2629/2682), 15.67 MiB | 10.32 MiB/s   
remote: Total 2682 (delta 1395), reused 2514 (delta 1316)[K
Resolving deltas: 100% (1395/1395)   
Resolving deltas: 100% (1395/1395), done.

I omitted most of the lines but you can understand how it is, it shows the progress from 0% to 100% for all actions.

Is there a way to save the cat command output to a file, exactly the same way as shown in the first output above please?

Thank you.

Upvotes: 0

Views: 1431

Answers (1)

entrez
entrez

Reputation: 301

here are three easy options (one & two are the same as my comments above):

  1. you can use regex-based text substitution in an editor like vim to edit the file, i.e. open the file, type : and run the substitution %s/^.*^K//, where ^K is written by typing Ctrl+V, then Ctrl+K
  2. you can use sed to edit the file in the same way:
    sed -i '' $'s/^.*\x0B//' /var/log/bitbucket.log
  3. you can use sed to edit the stream as it's being piped into the file in the first place:
    git clone --progress "https://giturl/repo.git" 2>&1 | sed $'s/^.*\x0B//' >/var/log/bitbucket.log

when I run git clone --progress on my system I get cr characters instead of vertical tabs, so I originally had \r instead of \x0B.

Upvotes: 2

Related Questions