My question is simple, specially to those familiar with Vim's Tabularize plugin. I want to tabularize the output I get from another command in the shell. For instance, given the following command yielding the given output:
$ mpc playlist
Metallica - Ride the lightning - The call of Ktulu
Metallica - Master of puppets - Master of puppets
Metallica - Master of puppets - Orion (Instrumental)
Nirvana - Nevermind - Smells like teen spirit
Metallica - ...And justice for all - One
Metallica - ...And justice for all - ...And justice for all
Metallica - Kill'em all - Seek and destroy
Metallica - Metallica - Wherever I may roam
Metallica - Metallica - The god that failed
What I need is a command that I can pipe this output to, and get the following
$ mpc playlist | tabularize --delimiter=" - "
Metallica - Ride the lightning - The call of Ktulu
Metallica - Master of puppets - Master of puppets
Metallica - Master of puppets - Orion (Instrumental)
Nirvana - Nevermind - Smells like teen spirit
Metallica - ...And justice for all - One
Metallica - ...And justice for all - ...And justice for all
Metallica - Kill'em all - Seek and destroy
Metallica - Metallica - Wherever I may roam
Metallica - Metallica - The god that failed
Any ideas?
The command you're looking for is column.
Try mpc playlist | column -t -s '-' -o '-'.
Sadly, this won't work if you have '-' characters in the input, and specifying ' - ' will columnise by spaces as well, not by the entire string.
** Match one-or-more of any sign: '.*' (greedy till second hyphen)
** Start of wanted pattern: '\zs' (Vim syntax)
** Pattern to match: ' -'
:%Tab /.*\zs -/
Related
I have a build folder in perforce that keep tracks of all my builds but the files inside it have different revision numbers (because they are / are not affected from different builds), so in the same folder i have files with revision #1200 and other with revision #2000.
I initially was thinking to obliterate the old revisions from p4admin, since there is the option "obliterate up to revision", but in the case of this folder I'm not sure how this will behave.
There is any way in p4 for keeping only the last 2 revision of all the files in that folder? Or the only doable way is writing a script for checking each file's revision before obliterating it?
Perforce doesn't have an additive relative revision syntax, unfortunately, so you can't use #head-2 or anything like that.
The easiest way to do something like this IMO is to create a label with the #head-2 revisions, which you can do iteratively using the #< relative revision specifier on the label itself:
# start by labeling #head
C:\Perforce\test>p4 tag -l minus2 ...#head
//stream/main/0.f1#3 - added
//stream/main/1.15#4 - added
//stream/main/1.16#1 - added
//stream/main/1.17#1 - added
//stream/main/1.18#2 - added
//stream/main/2.f1#5 - added
//stream/main/2.f2#4 - added
# now replace everything in the label with the previous revision
C:\Perforce\test>p4 labelsync -l minus2 "...#<minus2"
//stream/main/0.f1#2 - updated
//stream/main/1.15#3 - updated
//stream/main/1.16#1 - deleted
//stream/main/1.17#1 - deleted
//stream/main/1.18#1 - updated
//stream/main/2.f1#4 - updated
//stream/main/2.f2#3 - updated
# now do it again, bringing us to #head-2
C:\Perforce\test>p4 labelsync -l minus2 "...#<minus2"
//stream/main/0.f1#1 - updated
//stream/main/1.15#2 - updated
//stream/main/1.18#1 - deleted
//stream/main/2.f1#3 - updated
//stream/main/2.f2#2 - updated
Now the label has all the latest revisions that I want to obliterate. I'll double-check with p4 files -a before doing p4 obliterate:
C:\Perforce\test>p4 files -a #1,#minus2
//stream/main/0.f1#1 - add change 72 (text)
//stream/main/1.15#2 - edit change 77 (text)
//stream/main/1.15#1 - branch change 73 (text)
//stream/main/2.f1#3 - integrate change 81 (text)
//stream/main/2.f1#2 - integrate change 78 (text)
//stream/main/2.f1#1 - branch change 74 (text)
//stream/main/2.f2#2 - integrate change 79 (text)
//stream/main/2.f2#1 - branch change 75 (text)
C:\Perforce\test>p4 obliterate -y #1,#minus2
//stream/main/0.f1#1 - purged
//stream/main/2.f1#2 - purged
//stream/main/2.f1#3 - purged
Deleted 4 label 24 integration 8 revision record(s).
I'm piping output from one command into a second:
mpc listall | mpc add
mpc listall returns the following data (can output 1 or more lines):
Dare - 16 - I´ll Be Your King.mp3
When piping it into the next command, it seems that my shell (Ash on BusyBox) converts the ´ into an asterisk, as I get the error
error adding Dare - 16 - I*ll Be Your King.mp3: No such directory
Manually adding double quotes works! like this:
mpc add "Dare - 16 - I´ll Be Your King.mp3"
So, I tried adding those by sed and awk, but in those cases the backtick gets converted to an asterisk again:
mpc listall | sed 's/^/"/;s/$/"/'
returns:
"Dare - 16 - I*ll Be Your King.mp3"
So, question is, is there a way to pass backticks, or actually any character, as is, into another command without conversions?
By the way, obviously, it's quite bad to have this character in the file name in the first place, but I want my code to be robust and able to handle anything thrown at it.
Not a direct solution the problem, but a work-around (that's actually better, because it uses the API) in python using the python-mpd2 library:
myMpdClient = MPDClient()
myMpdClient.connect("localhost", 6600) # connect to localhost:6600
myMpdClient.findadd('base','directory-name')
myMpdClient.close()
I'll accept a working solution to the actual proposed problem, instead of this one, if someone posts a working solution.
I have a log file, in this pattern:
IP - - [date] "command" response time
I want to search in the log the lines which contains the ip:68.45.3.1 and part of the command: "/api/con"
So this is a correct result:
68.45.3.1 - - [05/Nov/2015:03:48:25 -0500] "GET /5.0/api/con/1" 20:01
How can I do it?
Try something like:
zgrep "^68.45.3.1.*\/api\/con" access.log.*.gz
assuming of course that your files are something like access.log.10.gz etc. (change the name of the file if this isn't the case).
I'm trying to clean up a bunch of yaml files in vim. The yaml files are fixtures for tests, and they contain literal strings of XML. They look like:
-
- "<xml>blah blah blah …1000 characters later</xml>"
- "<more>…</more>"
I want them to look like:
-
- >
<xml>
<nicely>formatted</nicely>
…
</xml>
- >
<more>
…
</more>
I strip the quotes, put the cursor at the beginning of the unformatted xml and hit >, enter, <tab>, I get
-
- >
<xml>…
But then I try to format the xml the only way I know how: shift-v to select the line. :'<,'>!xmllint --nocdata --format - | awk 'NR>1' to format the xml, and I get
-
- >
<xml>
<nicely>formatted</nicely>
…
</xml>
and then I have to reselect the xml and use 2>> to reindent.
Is there a better way to maintain the indentation when executing a ! command in Vim?
Your question doesn't state this outright, but it somewhat implies that vim is the reason the indentation is stripped, so just to be clear, the indentation is being taken out by xmllint.
You could try to save the indentation first, but that could be confusing if the indentation is different amongst the different lines. In this case it probably makes more sense from looking at the commands you are running to just add the indentation later - you can do it automatically by adding it to your command filter, such as:
:'<,'>!xmllint --nocdata --format - | awk 'NR>1' | sed -e 's/^/\t/'
What do plus and minus signs at the start of lines mean in cron syntax?
+ 0 9 * * * /usr/bin/curl -k http://www.example.com/cron/deactivate_users
- 10 8 * * * /usr/bin/curl -k http://example.com/cron/delete_users
As of the minus sign:
If a line inside a crontab starts with a '-' this will prevent cron from writing to the syslog about the execution of the command.
See manpage (5) of crontab.
There is no + or - */2 is there I think you have seen the above syntax somewhere where + means to add the line to curl and call deactivate_users and remove i.e - to remove delete_users or in short words to replace delete_users cronjob with the new cronjob of deactivate_users.
Thanks & Regards,
Alok Thaker
It (i.e. your lines starting with + or -) probably is the output of some GNU diff (or some other diff), so it is a patch file.
You may apply that patch with the patch command. Try perhaps patch < your.diff(or else patch -p0 < your.diff) where your.diff contains such lines starting with + or - (and also a few previous ones).