Wikipedia:Reference desk/Archives/Computing/2017 April 3
Computing desk | ||
---|---|---|
< April 2 | << Mar | April | May >> | April 4 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
April 3
[edit]bash/sed problem=
[edit]Hi. ubuntu linux. I have a file that looks like this:
2 23 9453
and I want to automatically create a file that looks like this:
foo "bar 2" baz foo "bar 23" baz foo "bar 9453" baz
(the actual file is thousands of lines long and I need to do this conversion hundreds of times). Can anyone suggest a way to do this using a bash script? I am currently defining an emacs macro but I want to automate it. thanks in advance, Robinh (talk) 01:34, 3 April 2017 (UTC)
- You could use sed to substitute the whole line, something like
sed -e 's/^\(.*\)$/ foo "bar \1"\n baz/'
- I cannot test it for you though. awk is simpler for this.
- In bash you should be able to do a while loop, the test is read a variable, and then echo it with the correct text. But since I am not confident I would get the syntax 100% without a test I wont insert it here. Graeme Bartlett (talk) 01:57, 3 April 2017 (UTC)
- . I didn't know you could putResolved
\n
in to the replacement part in sed. Thanks! Robinh (talk) 02:01, 3 April 2017 (UTC)- I also didn't think to use the bracket notation to keep the number in sed's memory. Robinh (talk) 02:03, 3 April 2017 (UTC)
- You can also use backslash-newline in the replacement part if you find it more legible; and since you want the entire original and not just a selected part of it, you can use & in the replacement. I'd write:
- I also didn't think to use the bracket notation to keep the number in sed's memory. Robinh (talk) 02:03, 3 April 2017 (UTC)
sed 's/.*/foo "bar &"\ baz/'
- Note, however, that if you do it this way, any whitespace on the line before the "baz" is significant and will go in the final output. --76.71.6.254 (talk) 18:45, 3 April 2017 (UTC)
- It's pretty straightforward to do it with bash alone -- something like this:
while read n; do echo foo \"bar $n\"; echo baz; done
- CodeTalker (talk) 18:13, 3 April 2017 (UTC)
- You could have a file containing the replacement, like (part.txt)
foo "bar thing" baz
- and another file with the replacements (list.txt)
2 23 9453
- and then run
for a in $( cat ./list.txt ) ; do sed "s/thing/$a/g" < part.txt >> final.txt ; done
There is a way of getting a file intofor
, but I can't remember what it is; however this will work. LongHairedFop (talk) 19:00, 3 April 2017 (UTC) - Just trying to make it more organized:
while IFS='' read -r n; do printf 'foo "bar %s"\nbar\n' "$n"; done
(Shouldn't make a difference as you are just taking in numbers.mapfile
with somearray=("${array[@]/#/PREFIX}") array=("${array[@]/%/SUFFIX}")
can be fun too...) --Artoria2e5 contrib 00:28, 4 April 2017 (UTC)
- and then run
for good measure, gawk: gawk '{printf("foo \"bar %d\"\n",$0);print "baz";}' < file.txt
Asmrulz (talk) 20:42, 3 April 2017 (UTC)
speaking of emacs, this should be doable in elisp alone. Asmrulz (talk) 20:48, 3 April 2017 (UTC)
elisp only, works on the current buffer, outputs to a temp buffer called "output-(name of old buffer)", use at your own risk:
(global-set-key [f6] (lambda () (interactive) (let* ((k (current-buffer)) (m (concat "output-" (file-name-base (buffer-file-name k)))) (n (with-current-buffer k (widen) (buffer-string))) (o (split-string n "\n" t))) (with-output-to-temp-buffer m (mapc (lambda (a) (princ (concat "foo \"bar " a "\"\nbaz\n"))) o)))))
Asmrulz (talk) 22:12, 3 April 2017 (UTC)
Samsung Lock-Lock Screen
[edit]Samsung phones, as with all Android phones, has a lock screen. They also have a second lock screen that appears after the lock screen has been on for a minute or so. What is the second lock screen called? For reference: I turned on notifications for the lock screen. If I am in the initial lock screen, I see them. Then, the phone locks a second time to the other screen and all it shows is a clock. There is an icon indicating that notifications are present, but the notifications are not shown. Looking for documentation is difficult because I don't know what the lock-lock screen is actually called. 209.149.113.5 (talk) 14:31, 3 April 2017 (UTC)
- That is the lock screen with "Hide Content" enabled. (Sometimes called the "Hidden Content lock screen".)
- You can change this behavior in the "Sound and Notifications" setting screen with the "Notifications on Lock Screen" setting. (You can change it to "Do not show notifications", "Hide Content", or "Show Content".) ApLundell (talk) 21:03, 3 April 2017 (UTC)
- It is called the "Always On" screen. Under Settings-Display you will find a setting to turn it off or change what it shows. It is very limited. It can show a clock, the calendar, or random pictures. When I first got my S7, I worried that it was on all the time (as the name implies). It turns off if you put your phone in your pocket or a purse or you turn your phone over so the screen is face down. 71.85.51.150 (talk) 22:42, 3 April 2017 (UTC)
- Found it by googling "samsung always on". Says that it works with few apps, mainly just Samsung apps. So, I have to use Samsung's txt app, not the Verizon txt app to be compatible with it. 209.149.113.5 (talk) 13:06, 4 April 2017 (UTC)
Can i safely remove Clementine in Ubuntu?
[edit]I can't remember if I installed Clementine or it was bundled with Ubuntu 16.04. Tried Google searching but i'm only getting instructions on how to install it. Thanks ツ Jenova20 (email) 20:25, 3 April 2017 (UTC)
- Clementine is a branch of the Amarok music player. You don't need it. You can remove it. Just use your favorite package manager to remove it. 71.85.51.150 (talk) 22:43, 3 April 2017 (UTC)
- Thanks ツ Jenova20 (email) 20:06, 4 April 2017 (UTC)
- Just make sure when you do that it's not lost and gone forever.Yes that was corny as hell and I just don't care. ᛗᛁᛟᛚᚾᛁᚱPants Tell me all about it. 20:21, 4 April 2017 (UTC)
- Old and corny! *Thumbs up* ツ Jenova20 (email) 09:13, 5 April 2017 (UTC)
- Just make sure when you do that it's not lost and gone forever.Yes that was corny as hell and I just don't care. ᛗᛁᛟᛚᚾᛁᚱPants Tell me all about it. 20:21, 4 April 2017 (UTC)
- Thanks ツ Jenova20 (email) 20:06, 4 April 2017 (UTC)