Concat string into file [closed] - unix

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a file with the following content (I placed 3 lines for example):
12743002785468 |MOVIL APPLE IPHONE4 16GB BLANCO |NVEN |Centro de Atención VIP |0862034032
12747002147595 |MOVIL APPLE IPHONE4 16GB BLANCO |NVEN |Centro de Atención VIP |0862033996
I have a variable date (20140430) I want to concatenate the beginning of each record like this:
20140430|12743002785468 |MOVIL APPLE IPHONE4 16GB BLANCO |NVEN |Centro de Atención VIP |0862034032
20140430|12747002147595 |MOVIL APPLE IPHONE4 16GB BLANCO |NVEN |Centro de Atención VIP |0862033996
I tried to use this:
cat /home/file.txt | awk '{print "'"20140430"'""|"$0;}' > /home/file.txt
and
sed -i 's/^/20140430|/' /home/file.txt > /home/file.txt
But not work and i could not do that to my file of 180,000 records. Anyone have another idea how I can concatenate? The operating system is SunOS 5.11 sun4v sparc sun4v 11.1
Thank you very much in advance

You can also loop and append:
while read line; do
echo 20140430'|'$line
done < /home/file.txt > /home/file.txt.tmp
mv file.txt.tmp file.txt

Related

Is there a cipher method that uses 9 digit(starts with 8,9 or else) and 10 digit(only starts with 1) [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 days ago.
Improve this question
1752462448 1933193007 1667526190 1684632419 1869767777 1886400099 1869426529 1953784163 1751999854 1953705777 808924214 943272760 825768241 858992688 876162865 808924214 959918133 892810033 825832761 808726350 1162236485 1412330081 1912602624 there is the cipher.
i tried dcode.fr Cipher Identifier and it says this is base36. yes i found something with it like a another cipher. i tried to decode it too but got nothing.
Example in Python for its universal intelligibility:
c = '1752462448 1933193007 1667526190 1684632419 1869767777 1886400099 1869426529 1953784163 1751999854 1953705777 808924214 943272760 825768241 858992688 876162865 808924214 959918133 892810033 825832761 808726350 1162236485 1412330081 1912602624'
b = [bytes.fromhex(
f'{int(a):08x}').decode() for a in c.split()]
print(''.join(b).rstrip('\x00'))
https://cdn.discordapp.com/attachments/1074689381891330049/1074697055731195904/NEFRET.rar
Note that b is the following list (with the last element 'r\x00\x00\x00'):
['http', 's://', 'cdn.', 'disc', 'orda', 'pp.c', 'om/a', 'ttac', 'hmen', 'ts/1', '0746', '8938', '1891', '3300', '49/1', '0746', '9705', '5731', '1959', '04/N', 'EFRE', 'T.ra', 'r\x00\x00\x00']
Therefore, wee need to remove all trailing ␀ (U+0000, Null) characters (see .rstrip('\x00') in the last line of above code snippet).

R - what does this tapply() function do? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Please excuse my terrible knowledge of the language - just started looking at it a few hours ago.
I'm trying to understand this code and what it produces but quite unsure. Given that the value of inclusions is 10, why is the output what it is?
seps <- tapply(diff, nonCore, function(x) sort(x)[inclusions])
Outputs
"","x"
"ab",23
"ad",15
The value of diff is
"","x"
"1",31
"2",43
"3",37
"4",22
"5",27
"6",13
"7",24
"8",7
"9",26
"10",29
"11",2
"12",15
"13",10
"14",38
"15",23
"16",21
"17",46
"18",10
"19",20
"20",46
"21",20
"22",32
"23",26
"24",11
"25",16
"26",2
"27",13
"28",4
"29",15
"30",18
"31",13
"32",26
"33",1
"34",27
"35",12
"36",10
"37",35
"38",21
"39",9
"40",35
The value of nonCore is
"","x"
"1","ab"
"2","ab"
"3","ab"
"4","ab"
"5","ab"
"6","ab"
"7","ab"
"8","ab"
"9","ab"
"10","ab"
"11","ab"
"12","ab"
"13","ab"
"14","ab"
"15","ab"
"16","ab"
"17","ab"
"18","ab"
"19","ab"
"20","ab"
"21","ad"
"22","ad"
"23","ad"
"24","ad"
"25","ad"
"26","ad"
"27","ad"
"28","ad"
"29","ad"
"30","ad"
"31","ad"
"32","ad"
"33","ad"
"34","ad"
"35","ad"
"36","ad"
"37","ad"
"38","ad"
"39","ad"
"40","ad"
You should supply the code to construct the vectors diff and nonCore, as it is those who could help you need to do massive edits...
That said, what is happening is that your sorting the combination of the vectors according to ab and and ad. ab matches against the first 20 in diff and ad the last 20. Then you just subset the list that is created with the element number that is given by inclusion.
It's the same as running the function without [inclusion] and doing this afterwards:
sep[[1]][10]
sep[[2]][10]

Find the value of a variable and replace it with new value in UNIX [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to access a text file and read some of its contents to change them with a new value.
This Find and Replace is really helpful but my requirement is slightly different.
Say if these are my file contents
image.description=Template Image 08182015
image.version=1.3.111
baseline.name=001_08_18_2015
I want to change them to
image.description=Template Image 08192015 #19 instead of 18
image.version=1.3.112 #112 instead of 111
baseline.name=001_08_19_2015 #19 instead of 18
At any point of time I will not be knowing what is the value of each variable but all I know is the variable name like "Image version" So now I need some script to find what is the value of variable image.version and auto increment the value to the next possible integer.
Any suggestions/ thoughts?
With GNU awk for the 3rd arg to match():
$ awk 'match($0,/(image\.version.*\.)(.*)/,a){$0=a[1] a[2]+1} 1' file
image.description=Template Image 08182015
image.version=1.3.112
baseline.name=001_08_18_2015
For the others since no arithmetic is involved you should be able to just use gensub() similarly.
Or, maybe this is the kind of thing you're looking for:
$ cat tst.awk
BEGIN { FS=OFS="=" }
$1=="image.description" { match($2,/.* ../); $2=substr($2,1,RLENGTH) substr($2,1+RLENGTH,2)+1 substr($2,3+RLENGTH) }
$1=="image.version" { match($2,/.*\./); $2=substr($2,1,RLENGTH) substr($2,1+RLENGTH)+1 }
$1=="baseline.name" { split($2,a,/_/); $2=a[1]"_"a[2]"_"a[3]+1"_"a[4] }
{ print }
$ awk -f tst.awk file
image.description=Template Image 08192015
image.version=1.3.112
baseline.name=001_08_19_2015

Is there a formatter/beautifier for NGINX config files? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I know this may sound a little stupid, but one of my NGINX config files is a piece of crap when it comes to formatting. It works and all but that's about it.
I tried to find some kind of beautifier or formatter, like http://jsbeautifier.org/ but then for nginx config files instead of javascript, but no luck so far.
I hope anyone would have a suggestion. There are no requirements, as long as it can format quickly / lazily made NGINX config files!
Thanks!
I found a few projects which might suit your needs:
Nginx Formatter (python) by 1connect
you can get it here
Nginx beautifier (js/nodejs) by vasilevich
nginxbeautifier.com which lets you format configs quickly in a web browser.
you can get a command line tool also on the same site to run it locally.
If your block lines end with {'s and }'s, this simple indenter could help you a bit.
It does not format all your configs, it only fixes indentation.
Original in awk (source):
#!/usr/bin/awk -f
{sub(/^[ \t]+/,"");idx=0}
/\{/{ctx++;idx=1}
/\}/{ctx--}
{id="";for(i=idx;i<ctx;i++)id=sprintf("%s%s", id, "\t");printf "%s%s\n", id, $0}
Or rewritten in python:
INDENT = ' ' * 4
def indent(contents):
lines = map(str.strip, contents.splitlines())
current_indent = 0
for index,line in enumerate(lines):
if (line.endswith('}')):
current_indent -= 1
lines[index] = current_indent * INDENT + line
if (line.endswith('{')):
current_indent += 1
return ('\n').join(lines)
There is a fork of http://jsbeautifier.org/ for nginx here: https://github.com/vasilevich/nginxbeautifier

Convert MATLAB code to R [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there a tool for converting MATLAB code to R?
I have a lot of code that needs to be converted from MATLAB to R. It doesn't have to be accurate, but it will be helpful in giving a head start.
Paul Gilbert provides a rough Bash script that could get you started (he claims it will convert about 80% of the way) on the R mailing list:
#!/bin/csh
cp $1 $2
ex -s $2 <<eof
g/%/s//#/g
g/function\(..*\)=\(..*\)(\(..*\)/s//\2 <-function( \3 { \1/
g/end/s// } #/
g/for\(..*\)=\(..*\):\(..*\)/s//for ( \1 in \2 : \3 ) {/
g/_/s//./g
g/;/s///g
g/==/s//##/g
g/=/s//<-/g
g/##/s//==/g
g/zeros(/s//matrix(0,/g
g/ones(/s//matrix(1,/g
g/eye(/s//diag(1,/g
g/\/s//solve(,)/g
g/fsolve('\(..*\)'/s//ms(~\1 /g
g/param(\(..*\))/s//param[ \1 ] /g
g/var(\(..*\))/s//var[ \1 ] /g
g/mod1(\(..*\)/s//mod1[ \1 /g
wq
eof
No there is no easy conversion. Some will translate nearly exactly, some will translate only with great pain and suffering. At least you'll be using R though! Start here to work out analogous functions and syntax:
http://cran.r-project.org/doc/contrib/R-and-octave.txt
http://cran.r-project.org/doc/contrib/Hiebeler-matlabR.pdf
When you get stuck please ask specific questions here. This is really too vague as it stands, though those reference cards will help with getting started.
An alternative to translating the code would be to call MATLAB from within R, using the RMatlab package.
I have not tried RMatlab, but the package description states:
This package provides methods to read
and write MAT files. It also makes it
possible to communicate (evaluate
code, send and retrieve objects etc.)
with Matlab v6 or higher running
locally or on a remote host.
Please see the comments on this issue:
URL:https://mandymejia.wordpress.com/2014/08/18/three-ways-to-use-matlab-from-r/
She mentions several options:
Option 1: Run a single MATLAB command at a time using system()
Option 2: Use R.matlab to send code to the MATLAB server
Option 3: Write an entire MATLAB program using writeLines() and run using system()

Resources