Split json file into multiple flowfile [closed] - apache-nifi

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a json file such as below, i need to split this flowfile into numbers of flowfile as per each line
Input flowfile:
{a:122, b: 12, c: dev}
{b: 19, c: dev}
{a:111, b: 12, c: roman,d: 2.3}
Output Flowfile will have 3 files with each row.
Splitjson is just just spliting the first line, please suggest

Do you have downstream processors that expect one JSON per flow file? Otherwise you may be able to skip the Split entirely and just use the Record processors (ConvertRecord, PutDatabaseRecord, e.g.). The JsonTreeReader (in later versions of NiFi) accept the one-JSON-per-line format (even though that's not valid JSON per se). If you do need one JSON object per flowfile, Bryan's suggestion of SplitText with a Line Count of 1 is spot-on.

SplitText with line count of 1

Related

Laravel How to filter inputs before going to the DataBase? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
Laravel How to filter inputs before going to the DataBase
what shoud i do to filter my inputs before saving to the database? i want it to be uniformed in like this format "Name" a uper case followed by lowercase.
in some cases like when the user register a full caps name i want it to be re format as the example "Name"
there's an especific PHP function to do what you need: ucfirst(). This function turns to Uppercase the first char from a string.
For example:
//If $request->name is 'JoHn' or whatever
$filtered_name = ucfirst($request->name);
//Returns 'John'
If is a case with two names, you can use the ucwords() PHP function (Turn first letter uppercase of every word from a string)
//If $request->name is 'OlivER JAMES'
$filtered_name = ucwords($request->name);
//Returns 'Oliver James'
Hope this help you.

Ruby snippet for reading lines block [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am new to ruby and seeking help.
We got the csv files having the column with data shown below. Using the csv parser and fetch the column data for each in a variable.
And we want to change column data from csv file to line shown below and write to a file:
FROM
---
- - status
- New
- Delivered
TO
status from New to Delivered
Thanks #igian for help
---
- - status
- New
- Delivered
- - Milestone
- Sprint1
- Sprint
I was struggling for this. I tried to use y.second but it fails, please correct what I am doing wrong.
Looks like a YAML file, see https://ruby-doc.org/stdlib-2.6.2/libdoc/yaml/rdoc/YAML.html
Load the file then handle the array:
require 'yaml'
y = YAML.load_file( 'the_file.yaml' )
y #=> [["status", "New", "Delivered"]]
words = y.first
p "#{words[0]} from #{words[1]} to #{words[2]}"
#=> "status from New to Delivered"

Adding a '-' sign before any phone number based on a condition [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 4 years ago.
Improve this question
I need to add a - sign before any phone number ending with } and remove that }
For example, consider this sample file:
*My phone number is 9999999999}<br>
Ram is calling to 88888888}<br>
653426} Rohan is trying to call 777777777*
Expected output:
*My phone number is -9999999999<br>
Ram is calling to -88888888<br>
-653426 Rohan is trying to call 777777777*
This will do the trick:
sed -i 's/\s\([0-9]*\)\}/ -\1/g' vv.txt
Description:
vv.txt is the file from the sample provided by you
\s\([0-9]*\)\} : will capture everything that is enclosed in a space and is a digit upto }
-\1/g : here we are replacing everything we captured in between space \s and symbol } in the previous step, with a negative sign
the output on the sample file is:
*My phone number is -9999999999<br>
Ram is calling to -88888888<br>
Rohan is trying to call 777777777*
To take care of the additional condition mentioned in comments you can do two things:
1.
sed -i 's/\([0-9]*\)\}/ -\1/g' vv.txt
but this will add a space in front of - if the line begins with the number as you said.
Alternatively if you don't want the space.
2.
sed -i 's/\s\([0-9]*\)\}/ -\1/g;s/^\([0-9]*\)\}/-\1/g' vv.txt

how to add list of strings to a text file in ruby [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 8 years ago.
Improve this question
I have list of strings. I am trying to append those string values to a text file.
Here is my code:
java_location = "#{second}#{first}"
The output of java_location is:
1.6.0_43/opt/oracle/agent12c/core/12.1.0.4.0/jdk/bin/java
1.6.0_43/opt/oracle/agent12c/core/12.1.0.4.0/jdk/jre/bin/java
1.5.0/opt/itm/v6.2.2/JRE/lx8266/bin/java
1.6.0_35/u01/app/oracle/product/Middleware/Oracle_BI1/jdk/jre/bin/java
I want this output writing into a text file.
How can i do that?
File.write('file.txt', java_location)
You want to open the file in append mode ('a') rather than readwrite ('w+') which truncates the existing file to zero length before writing
http://alvinalexander.com/blog/post/ruby/example-how-append-text-to-file-ruby
if first && second
java_location = "#{second}#{first}"
a << java_location
File.open("/home/weblogic/javafoundmodified.txt", 'a') do |file|
a.each {
|item|
file.puts item
}
end
end

Put numbers from a TSV file into an Array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a TSV file with one column in it. In that column are a bunch of numbers. The column has a header.
What is the most efficient way to get all of the numbers in that column into one array? (say like 2,000,000 numbers).
Example data:
income
2000\n
80000\n
50000\n
30000\n
I have tried:
File.readlines(path)[1..-1].collect{|salary| salary.gsub("\n",'')}
I want to have the following output:
[2000,80000,50000,30000]
What I have works but I'm not sure it is the most efficient because I would be reading a million rows into memory.
You can use CSV to do this, and it's really easy because you only have one column.
require 'csv'
CSV.read("/path/to/file.tsv").flatten
You can do something like:
array = []
File.foreach('test.txt') do |line|
next if $. == 1
line.chomp!
array << line if line > ''
end
p array
Which returns array as:
["2000", "80000", "50000", "30000"]
However, that is hardly a scalable solution. Depending on your machine you could run out of memory and take the app to a crawl. Instead, I'd strongly suggest using a simple database to store the values, and then operate on it. Databases are designed for this sort of purpose and can be extremely fast. I recommend using the Sequel gem for that.
$. is a special variable that is used to track the row number of the last read file, so, as foreach passes lines into the block, $. will increment. That makes skipping a particular line easy.
array << line if line > ''
is used to avoid appending empty/blank lines if the input file contains a trailing/terminating line-end.

Resources