GREP to find and change after a number in InDesign - grep

Is there a grep to find and change after a number input a force line break?
I have some like this
"1651651 John Doe"
The number is variable , and the name too.
I want to do that
"1651651
John Doe"

With GREP you can find a some variable. Say, a 'custom text variable' ~u. But it will be any 'custom text variable'. GREP tool can't tell if the variable contains the number of the name.
Or, if you sure that the first variable is a number and second one is a name always, you can use something like this:
Find what: (~u) (~u)
Replace to: ($1)\n\n($2)
Probably the task can be accomplished with a script. It depends on what exactly you have and what you want to get.

Related

how to select all cases containing a specific number in spss

can someone help me figure out how to select cases containing number 1, for example I coded nausea as side effect as 1 and was then noting it with other side effects as 1234 and now i wan to select all combinations with 1 but i cant figure out how. Or at least how to properly name what I am trying to achieve, since I am fairly new to spss so I can try to further search online.
I have tried variable = 1 and variable = 1 and neither worked and a few random commands that did not work either. I have put the variable as string and did not change anything either.
Once you change the variable into text you can use text search commands to find "1" within the text, like this for example:
compute nausea=(char.index(YourVariable,"1")>0).
char.index command searches for "1" in YourVariable - if it is there, it will output it's position in the text. If it isn't there, the output is 0. So nausea will get a value of 1 in all cases that contain "1" and will gat a value of 0 in all cases that don't.
NOTE - if you get as high as 10 in your numbers, this method will fail, as "10" contains "1". In order for any method to work here, you'd need to add a delimiter between the numbers when you record them, e.g. "1,3,8,17,22".

[splunk]: Obtain a count of hits in a query of regexes

I am searching for a list of regexes in a splunk alert like this:
... | regex "regex1|regex2|...|regexn"
Can I modify this query to get a table of the regexes found along with their count. The table shouldn't show rows with 0 counts.
regex2 17
regexn 3
The regex command merely filters events. All we know is each result passed the regular expression. There is no record or indication of why or how any event passed.
To do that, you'd have to extract a unique field or value from each regex and then test the resulting events to see which field or value was present. The regex command, however, does not extract anything. You'd need the rex command or the match function to do that.
Looks like | regex line is not needed. This is working for me. Notice the extra brackets.
| rex max_match=0 "(?P<countfields>((regex1)|(regex2)|..|(regexn)))"
| stats count by countfields

Syntax if variable includes a specific string of text

I was wondering if there was a syntax to select all account names that include a certain string of text.
For example, if I have a SPSS file that has 3 million account names, I'd want to look at only the account names that have a / TKS at the end. The account name could like like Stack Overflow / TKS.
You can use char.index to check whether a string includes a specific substring.
So for example:
compute containsTKS=0.
if char.index(account_name,"/ TKS")>0 containsTKS=1.
execute.
You can then use containsTKS to filter or select cases.
The solution eli-k provided checks if / TKS is inside the account_name, at any position.
If you want to check if the "/ TKS" text is at the end of your account_name, you need a slightly changed syntax:
compute containsTKS=0.
if char.index(account_name,"/ TKS")=char.len(rtrim(account_name))-5 containsTKS=1.
execute.
Then, as eli-k mentioned, "You can then use containsTKS to filter or select cases."

How to search a pattern like pattern using grep only?

I am searching list of names with pattern "japconfig".There are many files inside one directory. Those files contain names like ixdf_japconfig_FZ.txt,
ixdf_japconfig_AB.txt, ixdf_japconfig_RK.txt, ixdf_japconfig_DK.txt, ixdf_japconfig_LY.txt. But I don't know what are the names present after japconfig word. I need to list down all such names. Also my files contain ixdf_dbconfig.txt, but I don't want to print ixdf_dbconfig.txt in the output.
Each of my file contains one ixdf_japconfig_*.txt and ixdf_dbconfig.txt where * can be FZ,AB,RK,DK,LY. I can achieve my desired result by using grep and then awk to cut the columns.But I don't want to use AWK or other command. I want to achive using grep only.
I need to print below names.
ixdf_japconfig_FZ.txt
ixdf_japconfig_AB.txt
ixdf_japconfig_RK.txt
ixdf_japconfig_DK.txt
ixdf_japconfig_LY.txt
I don't want to print ixdf_dbconfig.txt.
When I tried using "grep -oh "ixdf_japconfig.*.txt" *.dat" command, I am getting below output.
ixdf_japconfig_FZ.txt ixdf_dbconfig.txt
ixdf_japconfig_AB.txt ixdf_dbconfig.txt
ixdf_japconfig_RK.txt ixdf_dbconfig.txt
ixdf_japconfig_DK.txt ixdf_dbconfig.txt
ixdf_japconfig_LY.txt ixdf_dbconfig.txt
where first column is my desired column. But I don't want to print second column. How can I change my code to print only first column?
grep -oh ixdf_japconfig_...txt *.dat
(Your .*. was matching most of the line.)

GREP create a list of words that contain a sting

I have a folder with a lot of text files and would like to get a list of all words in that folder that contain a certain string. So, e.g. there is words in the form of 'IND:abc', 'IND:cde', ... and I am looking for a way to get a list of all words starting with IND:, so something like:
[IND:abc, IND:cde, IND:...]
Can grep do that?
Cheers,
Chris
grep -ho 'IND:\w\+' * | sort | uniq
-h suppresses the filenames so that you will only get the text. -o prints only the matching path of the text. If you want to see the duplicates just remove the sort, and uniq.

Resources